expiration date coding

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
I have some coding below that provides a "license key" of sorts for the workbook. While writing it, I've messed something up (that's probably obvious) because each time I open the test workbook, it asks me for the license key. The "expirationdate" is a specified cell with an end date set 360 dates from the last inputted date. ideas here? It should only be asking for the license key when the date has expired...not everytime.
Code:
If ExpirationDate > Date Then
            Application.Visible = True
        ElseIf ExpirationDate < Date Then
            Application.Visible = False
            d = Application.InputBox("Your workbook license has expired. Please enter the registration key to renew your license.", namer)
            If d = CStr(Worksheets("Developer").Range("B23").Value) Then
                    Sheets("Developer").Range("C20") = Date
                    MsgBox "Welcome Back " & s, vbOKOnly, namer
                    Application.Visible = True
            End If
        End If
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi there. Dates are notoriously finicky when being compared. Initially I would try using the debugger to break on the 'Application.Visible = False' line and see what values it is actually comparing. Or put a msgbox in to display the value of ExpirationDate and Date immediately before that point.
 
Upvote 0
Hi there. Dates are notoriously finicky when being compared. Initially I would try using the debugger to break on the 'Application.Visible = False' line and see what values it is actually comparing. Or put a msgbox in to display the value of ExpirationDate and Date immediately before that point.



What an easy, good idea! Thank you!

The expirationdate was giving a blank return so I fixed it! thanks!
 
Upvote 0
good evening

So i went ahead, took your advice (it was good!) and came up with the following issues. I have attached the coding below. Basically using a msgbox and a few other means of playing with the dates, I'm still popping the same errors- in debug I still see the "expirationdate" as equal to "" yet in the msgbox it's correct. Evening putting msgbox year(expirationdate) gives me the correct value (2020).

Ideas?

Code:
Application.Visible = FalseDim s As String
Dim namer As String
Dim edate As String
Dim d As String
Dim ExpirationDate As Date


'edate = Sheets("Developer").Range("E37")            'expiration date
d = Sheets("Developer").Range("B39")                'registration key
ExpirationDate = DateValue(Sheets("Developer").Range("E37"))                   'expiration date
edate = Sheets("Developer").Range("E37")
namer = Sheets("Notes").Range("N4")                 'just a name




MsgBox Year(ExpirationDate)
MsgBox Year(Date)
Exit Sub

Else:
    If ExpirationDate > Date Then
        If ActiveWorkbook.name = "Master Voyage Report.xlsm" Then
             UserForm1.Show
        ElseIf ActiveWorkbook.name = "Current Voyage Report.xlsm" Then
             UserForm2.Show
        Else: UserForm3.Show
        End If
    Else:
TryAgain:
MsgBox ExpirationDate
MsgBox Date
MsgBox ExpirationDate < Now
        d = Application.InputBox("Your workbook date has expired. Please enter the registration key to renew your license.", namer)
        If d = False Then Exit Sub
        If d = CStr(Worksheets("Developer").Range("B39").Value) Then
            Sheets("Developer").Unprotect Password:=Worksheets("Developer").Range("B15:E15").Value
            Sheets("Developer").Range("C36") = Date
            MsgBox "Welcome Back " & s, vbOKOnly, namer
        Else
            MsgBox "Password Incorrect, Please try again.", vbCritical, name
            GoTo TryAgain
        End If
    End If
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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