MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Hiding macros


Posted by Baje on December 07, 2001 11:01 AM

Hi,
Is there any way you can prevent the user from accessing macros in a workbook, like password protecting them or something? The users would have read and execute rights, not write.


Posted by Michael on December 07, 2001 11:16 AM

The easiest way to hide the macros is to go to the Visual Basic Editor and select project properties. Here you want to select lock project for viewing and type in a password to use. Make sure that you record it somewhere because if you forget it, you will have a significant problem.

Posted by Tom Urtis on December 07, 2001 11:22 AM

To add to Michael's post...

As Michael, said, you can hide macros, by going to the VBE and clicking Tools > VBA Project Properties > Protection tab, select "Lock project for viewing", and enter your password.

One suggestion, this will not prevent anyone from running a macro, only from editing it. Some macros are written to be executed only when something else (i.e. a daily dowload or some manual activity) has taken place.

If you have macros that, if run, would mess up the spreadsheet, try prefacing the macro with an input box first, to require a passcode, as such:


Sub YourMacro()
Dim myPassword As String
myPassword = InputBox(prompt:="Please enter the password to proceed:", _
Title:="Password is required to run this macro.")

If myPassword <> "PASSWORD" Then
MsgBox prompt:="Click OK to return to Report.", _
Title:="Cancelled -- correct password not entered", _
Buttons:=16

Else

'ENTER CODE HERE

End If
End Sub

Posted by JACK JACK on December 07, 2001 11:46 AM

I have found just password protect the module and that will do then no one cas see PROTECT FROM VIEWING, no one will hack the password on that one

I hope thats all you need and invisable text is not such a good ideas and borders on virus codes..

rem.... the code will still run just un editable thats all.

I do not hide my codes as i share with anyone, and save as exported txt or bas files and as i wrote them i find i a few mins i can repair damage "keeps me in a job" most cant bastardise my codes i make them deliberatly complex with funny words, ok not good programming as such but comfusion works well.

HTH

Posted by Baje on December 10, 2001 8:54 AM

Thanks!!! Perfect!!!