Saturday, July 18, 2009

Excel Macros : VBA Expiry date for Excel Workbook

Many times we have a situation where we need to force users to use updated file and stop using the old version of worksheet. The only way to do so is to put expiry date for your workbook. User will not be able to work upon the file once the expiry date is crossed and will be forced to look for updated version.

You will need to copy this code to ThisWorkbook section of your workbook .
Private Sub Workbook_Open()
Dim Edate As Date
Edate = Format("31/08/2009", "DD/MM/YYYY") ' Replace this with the date you want
If Date > Edate Then
MsgBox ("This worksheet was valid upto " & Format(Edate, "dd-mmm-yyyy") & " and will be closed")
ActiveWorkbook.Close
End If
If Edate - Date < 30 Then
MsgBox ("This worksheet expires on " & Format(Edate, "dd-mmm-yyyy") & " You have " & Edate - Date & " Days left ")
End If
End Sub

Once the expiry date is crossed, user will get message and workbook will be closed by macro
Once the expiry date in with next thirty days, user will get warning message about expiry date and number of days left.

Download file containing Workbook Expiry Date Macro

4 comments:

  1. how do i convert numbers in words in xcel format??? m findin it very difficult...

    ReplyDelete
  2. can this run automaticaly once the user trys to open the file or do i have to run the macro?

    ReplyDelete
  3. can this run automaticaly once the user trys to open the file or do i have to run the macro?

    ReplyDelete
  4. Would the author be able to get back into an expried file, since once it expires it will not open?

    ReplyDelete