Time limit

  • Thread starter Thread starter Gordon
  • Start date Start date
G

Gordon

Hi...

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

Cheers

Gordon...
 
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.
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top