Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public Variables - password

Status
Not open for further replies.

Gavona

Technical User
Aug 27, 2002
1,771
GB
I am protecting a sheet with a password - not a high security thing just to avoid 'accidental' mishaps by users who don't understand the implications. Rather than hard coding the password throughout my modules, I wanted to set it using the Workbook_Open event.

So, in ThisWorkbook I included:
Code:
Public myPassword As String

Private Sub Workbook_Open()
myPassword = "password"
End Sub

And in other modules
ActiveSheet.Unprotect (myPassword)
ActiveSheet.protect (myPassword)
However this variable does not appear to be available to CommandButtons or other modules.

Any suggestions?

Gavin
 
How about finding someplace to store the password (not necessarily initialized at workbook startup)

For example create a userform. Put the password in the caption.

You can access it as Userform1.Caption
 
'MyPassword' in Thisworkbook module becomes r/w property of ThisWorkbook. It is accessible by:
ThisWorkbook.MyPassword
However, the user can find this variable in the object browser and get it in immediate window.
Another option is declaration in standard module:
Option Private Module
Public myPassword As String

The value of myPassword is still accessible in immediate window, but the module and variable name is not displayed in object browser.
You can also declare a public function in private module, the advantage is that the password is generated each time the function is called, so will never be reset.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top