Hi one and all,
This time I have come up with a RunOrNot Macro.The purpose of this macro is to restrict user to run the Main Macro (YOUR_MACRO) for once in a day.
Changes required in the code:-
In the Code below you have to change the YOUR_MACRO with your actual main macro.The text of Msgbox can be changed accordingly.
Sub RunOrNot()
ExDate = GetSetting("Excel", "Forum", "ExDate")
If Not IsDate(ExDate) Then
SaveSetting "Excel", "Forum", "ExDate", Format(Date, "DD-MM-YYYY")
MsgBox "This is the first and last time today that you are running the macro.", vbInformation
Call YOUR_MACRO
ElseIf (Date - DateValue(ExDate)) & 0 Then
MsgBox "This is the next day. Click OK to run the macro.", vbInformation
SaveSetting "Excel", "Forum", "ExDate", Format(Date, "DD-MM-YYYY")
Call YOUR_MACRO
Else
MsgBox "You have already run this macro today. So now you can't.", vbInformation
End If
End Sub
Actually, this macro uses Windows registry settings to save current day when the code is run for the first time in a day.
The benefit of using the Registries is that :-
If the user re-downloads the file (having this code inside) on the same computer, even then he will be restricted to run the Main Macro because the ExDate (Current Date) would have already been saved in the windows registry.
I hope you like the concept.
If you have any doubts in implementing it and understanding it then do comment.
Regards,
Vikas Gautam
Comments
Post a Comment