Microsoft Office Tutorials and References
In Depth Information
Forcing the User to Enable Macros
If DummySheet Is Nothing Then¶
MsgBox "Unable to find dummy sheet", vbCritical¶
Exit Sub¶
End If¶
'Turn off screen updating¶
Application.ScreenUpdating = False¶
For Each OtherSheet In ThisWorkbook.Sheets¶
OtherSheet.Visible = xlSheetVisible¶
Next OtherSheet¶
'Hide the Dummy sheet¶
DummySheet.Visible = xlSheetVeryHidden¶
'Mark the workbook as saved, because the user has not made any¶
'changes yet¶
ThisWorkbook.Saved = True¶
'Restore screen updating¶
Application.ScreenUpdating = True¶
End Sub¶
' * * * * *¶
Sub RunOnClose()¶
'This macro hides all the "useful"¶
'sheets, and displays the dummy sheet¶
'Variable declaration¶
Dim DummySheet As Worksheet¶
Dim OtherSheet As Object 'All sheet types¶
On Error Resume Next¶
Set DummySheet = ThisWorkbook.Worksheets("Macros disabled")¶
If DummySheet Is Nothing Then¶
MsgBox "Unable to find dummy sheet", vbCritical¶
Exit Sub¶
End If¶
'Turn off screen updating¶
Application.ScreenUpdating = False¶
'Show the Dummy sheet first, to avoid possible errors¶
DummySheet.Visible = xlSheetVisible¶
'Hide all except the dummy sheet¶
For Each OtherSheet In ThisWorkbook.Sheets¶
If Not OtherSheet Is DummySheet Then¶
OtherSheet.Visible = xlSheetVeryHidden¶
End If¶
Next OtherSheet¶
'Save the workbook¶
ThisWorkbook.Save¶
End Sub¶
' * * * * *¶
Sub Auto_Open()¶
'Run the ForceMacros macro when the workbook is opened¶
ForceMacros¶
End Sub¶
Exl
Search JabSto ::




Custom Search