Hide passwords in Macros

All2Cheesy

Board Regular
Joined
Mar 4, 2015
Messages
127
Hi all,

I've got various bits of code which refer directly to the password currently used to lock excel sheets. The code works fine, however, this causes a couple of issues.

Firstly, the code is not dynamic, and won't function correctly if the password has been changed
and secondly, if someone were to get a glimpse at the code, they would be able to see the password.

I used to have userinterface turned on which resolved this issue, but caused other issues down the line. Is there a way around the above issues?


Code:
Sub ShowHideReturnRates()
    
'Unlock Sheet
[COLOR="#FF0000"]ActiveSheet.Unprotect Password:="password"[/COLOR]
    
'Show/Hide Return Rates
    If Columns("L:T").Hidden = True Then
        Columns("L:T").Hidden = False
    Else
        Columns("L:T").Hidden = True
    End If
    
'Lock Sheet
[COLOR="#FF0000"]ActiveSheet.Protect Password:="password"[/COLOR]


End Sub

As always, your help is appreciated.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
hello

Worksheet password is weak & easily bypassed.

You can tie yourself in knots a little bit in stopping access to things, and it can be a bit of a pain (for you to implement).

Consider a strong VBA code password and workbook password; also using very hidden worksheets where appropriate.

To handle changing the worksheet password, perhaps a global variable in the code. Then you only have to change it in one place.

HTH
 
Upvote 0

Forum statistics

Threads
1,216,796
Messages
6,132,742
Members
449,756
Latest member
AdkinsP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top