How to make a Macro expire

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
929
Office Version
  1. 365
Platform
  1. Windows
I am hoping someone could help me with making a macro expire. Every month I have to make a change to a certain shared spreadsheet. The problem is sometimes I do not get to the sheet in time before the macro in it is used and the user gets inaccurate data. So I would like it if I am able to put a date in the VBA code at the beginning of the Macro that says if that date entered is equal to or greater, then display msg "Macro expired, requires update" and end the macro, otherwise go to next (aka run the macro).

How would I write something like this?

Thank you for your help.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Well, you can't store a dynamic value directly in VBA, so you'd have to store the date somewhere on a spreadsheet that you can check against, then make sure you update that date each month for the next round.

Very simple to get the idea:
VBA Code:
Sub CheckDate()
If Date >= Range("A1").Value Then
    'Display expiration message
    Exit Sub
Else
    'Run code as normal
End If
End Sub
 
Upvote 0
I actually figured it out from another post on this forum and it seems to be working:

VBA Code:
Const sPassword = "Password"
 Dim sUserInput
 If Date > CDate("06/09/2024") Then
    sUserInput = InputBox("Enter password to continue...", "Enter Password")
    If Not sUserInput = sPassword Then
        MsgBox "Macro expired, requires update"
        Exit Sub
    End If
 End If

Thank you though for your help! :)
 
Upvote 0
Solution
I actually figured it out from another post on this forum and it seems to be working:

VBA Code:
Const sPassword = "Password"
 Dim sUserInput
 If Date > CDate("06/09/2024") Then
    sUserInput = InputBox("Enter password to continue...", "Enter Password")
    If Not sUserInput = sPassword Then
        MsgBox "Macro expired, requires update"
        Exit Sub
    End If
 End If

Thank you though for your help! :)
Glad you got it figured out.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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
Back
Top