• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Macro for ExpirationCode

jwelker12

New Member
Hello I am trying to have my excel document lock up after a few months with this expiration code below but I'm having a few issues.

First issue the Macro code is incorrect for some reason and i can't figure it out.

Second issue the file lets people decide if they want to use the macros in the file and if they choose not to open the file with the macros then they are able to continue to edit the file even after the expiration date.

Is there a way to be able to do both without going crazy.


Here is my Code:

Code:
Sub Auto_Open()
ExpirationCode
End Sub

Sub ExpirationCode()
Dim ExpirationDate As Date
ExpirationDate = DateSerial(2015, 19, 2)
If Now() >= ExpirationDate Then
MsgBox “Trial Period ended on ” & CStr(ExpirationDate) & “.”
ThisWorkbook.Close savechanges:=False
End If
End Sub


I have attached a file example if anyone can help me.

Thank you
Justin
 

Attachments

  • Test 1.xls
    36 KB · Views: 1
Last edited by a moderator:
Justin

The DateSerial format is DateSerial(Year, Month, Day)
you had DateSerial(Year, Day, Month)

Use + to join strings in VBA

Code:
Sub ExpirationCode()
Dim ExpirationDate As Date
ExpirationDate = DateSerial(2014, 2, 19)
If Now() >= ExpirationDate Then
MsgBox "Trial Period ended on " + CStr(ExpirationDate) + "."
ThisWorkbook.Close savechanges:=False
End If
End Sub
 
As for the second part of your question about forcing users to Enable Macro's
This would require a macro and hence can't be achieved

You will need to educate your staff as to how and why they must enable macros

There is a technique which can be used and is described here
http://datapigtechnologies.com/blog/index.php/forcing-your-clients-to-enable-macros/
It only has a single sheet visible which has a warning message that macro's must be enabled
So unless a user enables macro's they only see this message
If they enable macro's, the sheet is hidden and other sheets are shown
 
Justin

The DateSerial format is DateSerial(Year, Month, Day)
you had DateSerial(Year, Day, Month)

Use + to join strings in VBA

Code:
Sub ExpirationCode()
Dim ExpirationDate As Date
ExpirationDate = DateSerial(2014, 2, 19)
If Now() >= ExpirationDate Then
MsgBox "Trial Period ended on " + CStr(ExpirationDate) + "."
ThisWorkbook.Close savechanges:=False
End If
End Sub

Hui,

I have attached a screenshot of an error message that i received with the ExpirationCode when I tried to apply it to my file.

Any Ideas?

Thanks
Justin
 

Attachments

  • Screen Shot 2014-11-19 at 10.56.34 PM.png
    Screen Shot 2014-11-19 at 10.56.34 PM.png
    27.5 KB · Views: 5
I have also had an issue with the Macro that forces users to enable macros but it is still able to work just want to maybe clean it up a little . I have attached a print screen of the error that I'm getting to see if anyone can help me out with this.
Thank you
Justin
 

Attachments

  • Screen Shot 2014-11-20 at 8.33.21 PM.png
    Screen Shot 2014-11-20 at 8.33.21 PM.png
    71.7 KB · Views: 1
Justin

I am sorry, But I can't assist with Excel Mac issues.

Anybody else running Excel Mac that can help Justin ?
 
Back
Top