Time limit

G

Gordon

Hi...

Is it possible to code a macro so that a file won't open after a certain date?

Cheers

Gordon...
 
F

FunkySquid

Hi, put this code in the ThisWorkbook module:

Private Sub Workbook_Open()
If DateValue(Now()) > DateValue("29/09/2008") Then ThisWorkbook.Close
False
End Sub

Change the "29/09/2008" to whatever date you want.

The False after the ThisWorkbook.Close is to save the changes.

Hope this helps.
 
J

JLGWhiz

You can also control it within the macro with an If ... Then statement:

Sub myMacro()
If Date >= DateValue("October 1, 2008") Then
Exit Sub
End If
'myMacro Code
End Sub
 
M

Mike H

Gordon,

It's extremely unlikely that any VB method would deter even a slightly
experienced user or a novice with access to Google. Both of replies you have
require macros enabled and if they aren't enable then the code doesn't
execute and the workbook opens.

Have a look at Chip Pearson's site who explores the problem in some depth
and points aout the shortcomings of any VB approach.

http://www.cpearson.com/excel/WorkbookTimeBomb.aspx

Mike
 
Top