Forced Macro Enable with Workbook Expire Date Code

adillard

New Member
Joined
Jul 11, 2006
Messages
26
First, I do know that there is no sure way to protect an Excel file. They don't provide a good security system. But I feel you can make it very hard for the unexperienced individulas.

I have found a Forced Macro Enable Code and I have tried to add an expire code to it without much excess. It does test , but when I apply it the Marco Enable works fine, but the Expire does not.

If someone could look at the "Expire" part below and tell where I went wrong, I would be greatful. Thank You

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
End Sub

Private Sub Workbook_Open()
UnhideSheets

MsgBox "This evaluation program will expire on 8/30/2006"
Dim staticdate As Date

staticdate = #8/1/2006#
If VBA.Now - staticdate < 30 Then

Workbooks.Open Filename:="c:\Evaluiation\Test.xls", Password:="*"

MsgBox "I'm sorry, the evaluation program you are trying to access has expired. You may purchase the full program with all functions from Sunflower-Dillard,Inc. Contact Sunflower-Dillard, Inc. at sunflower_teachers@XXXXX.com. Thank you."

MsgBox "This spreadsheet is no longer active. " & _
"Excel will shut down now", vbExclamation

End If

End Sub



Private Sub HideSheets()
Dim sht As Object

Application.ScreenUpdating = False

ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVisible

For Each sht In ThisWorkbook.Sheets

If sht.Name <> "Macros Disabled" Then sht.Visible = xlSheetVeryHidden

Next sht

Application.ScreenUpdating = True

ThisWorkbook.Save

End Sub

Private Sub UnhideSheets()
Dim sht As Object

Application.ScreenUpdating = False

For Each sht In ThisWorkbook.Sheets

sht.Visible = xlSheetVisible

Next sht

ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVeryHidden

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,141,756
Messages
5,708,333
Members
421,566
Latest member
7Nabisco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top