CleGG said:
i like this answer , but i am not verse enough to accomplish this. Can you walk me through this a little more?
thanks.
ENSURE THAT THE USER OPENS THE WORKBOOK WITH MACROS ENABLED.
This example has one working worksheet, "Working". To ensure that the user opens the workbook with macros enabled, introduce a second worksheet, "Warning". The following text is what appears on one of my own "Warning" sheets.
-----------------------------------------------------
Please enable macros when opening this workbook. If you disabled macros when you opened this book, please close it NOW without saving it, then reopen it with macros enabled.
If you cannot see any worksheets beside this one, you have opened the workbook with macros disabled. Close the workbook now WITHOUT SAVING CHANGES, then reopen it with macros enabled.
-----------------------------------------------------
This should be displayed in large red text with obnoxious thick borders and glaring background colors. The sheet should be password protected, and in VBA, use this command while constructing the sheet to prevent the user from being able to even select anything on the sheet:
Code:
activesheet.enableselection = xlunlockedcells
In the ThisWorkbook code module, you need these event procedures:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
lockup
End Sub
Private Sub Workbook_Open()
un_lock
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
lockup '' saves workbook in lockup routine
un_lock
End Sub
These two procedures probably belong in a regular module, but I had left them in the ThisWorkbook module without ill effects:
Code:
Private Sub lockup()
Application.ScreenUpdating = False
Application.EnableEvents = False
ThisWorkbook.Worksheets("Warning").Visible = xlSheetVisible
ThisWorkbook.Worksheets("Working").Visible = xlSheetVeryHidden
ActiveWorkbook.Save
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Private Sub un_lock()
Application.ScreenUpdating = False
Application.EnableEvents = False
ThisWorkbook.Worksheets("Working").Visible = xlSheetVisible
ThisWorkbook.Worksheets("Warning").Visible = xlSheetVeryHidden
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
The idea here is to always save with only the Warning sheet visible, so the user must use VBA to use the Working sheet. You lock up the workbook before quitting, and unlock it when it opens with macros enables. Also, you intercept the user's save, lock it up, do your own save and cancel theirs, then unlock it again. This is how you assure that the user always opens the file with macros enabled.
When I used this most, it was when people were just learning about macro viruses, and some of my less sharp-witted colleagues thought macro and virus were synonymous. (One guy even thought the V in VBA stood for Virus!) I don't work there anymore.
- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______