|
|
Question : Automatically Enable Macros
|
|
Hello, Experts!
I have a document that will be placed on a shared network drive that only certain users have access to. The document has a macro in it that, currently, the macro security must be set to low in order for macros to be enabled so that it will run.
Is there a way to digitally sign my macro or to automatically enable macros when individual users open the document?
|
Answer : Automatically Enable Macros
|
|
I see that on there. Does the "Main" page have any information on it that you don't want anyone to see? I will be away from EE for a while starting in a couple minutes, so I'll leave you with what I'm assuming will be your answers. To be safe, I would recommend saving a backup copy of the file as you have it now, on the .00001% possibility that something bad happens. I always do this, even though I've never had to use it.
Assuming that the "Main" page has no sensitive information on it (or no information on it at all), enter this text onto the "Main" page:
********** You need macros enabled to view this document. Please go to Tools, then Macros, then Security. If you want to enable macros on a file-by-file basis, change the security to Medium, but please remember to press "Enable Macros" when loading this document. If you want macros always enabled, change the security to Low.
After changing the security, please close this document and re-open it. Thank You. **********
Next, remove the code you have in the ThisWorkbook (which you pasted above), and enter the following:
'********** Private Sub workbook_open() Dim Password Sheets("Main").Select Password = InputBox("Enter your password", "Sheet Access") Select Case Password Case D25m25, "D25m25" Sheets("ASmith1").Visible = xlSheetVisible Sheets("ASmith2").Visible = xlSheetVisible Sheets("ASmith3").Visible = xlSheetVisible Sheets("ASmith4").Visible = xlSheetVisible Sheets("ASmith5").Visible = xlSheetVisible Sheets("Main").Visible = xlSheetVeryHidden Case 2345, "2345" Sheets("AJones1").Visible = xlSheetVisible Sheets("AJones2").Visible = xlSheetVisible Sheets("AJones3").Visible = xlSheetVisible Sheets("AJones4").Visible = xlSheetVisible Sheets("AJones5").Visible = xlSheetVisible Sheets("Main").Visible = xlSheetVeryHidden Case Else MsgBox "Incorrect password. Workbook will now close." ActiveWorkbook.Close End Select End Sub Sub Workbook_BeforeClose(cancel As Boolean) Sheets("Main").Visible = xlSheetVisible Sheets("Main").Move before:=Sheets(1) For ToClose = Worksheets.Count To 2 Step -1 Sheets(ToClose).Visible = xlSheetVeryHidden Next ToClose End Sub '**********
That should work exactly as you need it. In order for every hidden statement/etc to work, you will probably need to open the document, do what I said above, then save it. Next, open it again, enter your name/password, save it, and close it again. The next time you open it it will be what you need, it just has to be opened/closed a couple times (after changing initially) for the workbook modules to work correctly. After you have done that, try changing your macro setting to Medium (requiring the enable/disable macros window to appear when you open it). Try disabling the macros, and make sure that nothing is shown.
If the "Main" page has any sensitive information on it, or the above instructions don't work, let me know and I'll take a look at it later Matt
|
|
|
|
|