Share via

deactivate VBA code

Anonymous
2014-02-01T20:41:58+00:00

Dears,

kindly please i have a question related to VBA code that i want to determine a date that when match it, the running code will be deactivate,

that i want the operation of this code will go deactivated at #12:00:00 PM, 1-Mar-2014, the users can use this code till the mentioned date only.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-02-02T02:53:59+00:00

Here's an even more 'dastardly' solution: if the date is on or after the specified date, then the workbook immediately closes after an announcement that the license has expired.

This goes into the ThisWorkbook code module

Private Sub Workbook_Open()

  Dim termDate As Date

  termDate = #3/1/2014 12:00:00 PM#

  If Now() >= termDate Then

    MsgBox "The license on this software has expired.", _

     vbOKOnly + vbCritical, "License Expired"

    ThisWorkbook.Close

  End If

End Sub

If you'll set the VBAProject security to require a password to view the code, then they will have a difficult time even getting to their data.  While they can hold the [Shift] key while opening the file to stop the shutdown code from running, then none of the other VBA code in the workbook is going to work either.

If you do assign a password to the VBAProject, be sure to keep a copy of the file without that lockdown so that if you forget the password in the future, you'll have a copy you can open and work with easily.  I'd also actually 'write down' the VBAProject password in a .txt file and store it in the same folder on your computer with the source files.  That helps you remember it, and since presumably others don't have access to your computer, it's still secure.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2014-02-01T20:58:44+00:00

Hi,

Try this. As soon as the expiry date is gone then the code simply exits sub

Sub somesub()

Dim mydate As Date

' 1st March 2014

mydate = #3/1/2014 12:00:00 PM#

If Now() > mydate Then

Exit Sub

'your code

End If

Was this answer helpful?

0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-02-03T16:20:12+00:00

    @JLLatham 

    the question didn't related to the security somehow but concern some organization for the data

    i ask for how can i control the expiry date to modify or change it from another excel sheet

    Regards,

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-02-02T17:04:57+00:00

    Thank you for letting us know these solutions are working for you.

    Just remember that in in an Excel workbook there is no such thing as "really secure" - there are many tools that are found easily that will remove even the protection on a VBA Project.  Those usually cost some money, but others to unprotect workbook structures and worksheets are quite often free.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2014-02-02T15:52:23+00:00

    @JLLatham & Mike H..

    Thanks a lot for your following to get my answer your efforts are highly appreciated

    Regards,

    Was this answer helpful?

    0 comments No comments