FIFAWORLDCUP
New Member
- Joined
- Sep 16, 2016
- Messages
- 14
I have an xlsm file,hope to delete itself automatically after the date 2016/9/15,how to write the macro?
thanks in advance
thanks in advance
<code>Private Sub Workbook_Open()
If Now() > #1/1/2014# Then Call SuicideSub
End Sub</code> '
<code>Sub SuicideSub()
'courtesy Tom Ogilvy
With ThisWorkbook
.Saved = True
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
End Sub</code>
You cannot, and thank goodness you cannot, or virus makers would have a field day with this (if they could force you to enable malicious code).have the method that do not allow somebody disables macro before opening?
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Worksheets("INTRO").Activate
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name <> "INTRO" Then ws.Visible = xlSheetVisible
If ws.Name = "INTRO" Then ws.Visible = xlSheetHidden
Next ws
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Worksheets
If ws.Name = "INTRO" Then ws.Visible = xlSheetVisible
If ws.Name <> "INTRO" Then ws.Visible = xlSheetHidden
Next ws
End Sub
What Michael posted is Workbook event procedure code. In order for this code to run autoamtically, it MUST be placed within the pre-defined "ThisWorkbook" module in that workbook. If you place it in any other module, it will not work.Michael M - I came across this thread and hoping to get some clarity on the code you posted. I'm a VBA novice - do I put this code into one module or split into two modules? I've tried it both ways and I still can't get it to execute. Or if the intervening years you have a better way to force the user to enable macros, that'd work for me as well. Thanks for your help!