K0st4din
Well-known Member
- Joined
- Feb 8, 2012
- Messages
- 501
- Office Version
- 2016
- 2013
- 2011
- 2010
- 2007
- Platform
- Windows
Hello to all the Gods in this forum.
After a lot of searching on the internet, I was able to find what I needed.
But, somehow I can't understand this macro 100%.
To make it easier, I will attach a link to the page where various options and changes in the macro itself are commented, while in the last comment a final and a macro are given, which is set up properly.
I also downloaded the file, entered the macros and opened this LOG file.
The person who did it in the macro describes some numbers, and in the hidden LOG file gives others.
I don't understand these trial days, where they are written in the log file or in the macro itself?
I also can't understand, these words at the beginning and at the end - should they always be contained and numbers should be inserted between them?
In the description in the macro he gave examples, which number is equal to what, but the actually ready code (for continuation of the workbook or a new trial period) in the code - no number matches.
I am asking you for some clarification, I am only begging for that.
I am also posting the last code I am talking about and the link to the official page.
Thank you all for your cooperation.
Setting a Trial Period / Timer for Software Solutions | Experts Exchange
After a lot of searching on the internet, I was able to find what I needed.
But, somehow I can't understand this macro 100%.
To make it easier, I will attach a link to the page where various options and changes in the macro itself are commented, while in the last comment a final and a macro are given, which is set up properly.
I also downloaded the file, entered the macros and opened this LOG file.
The person who did it in the macro describes some numbers, and in the hidden LOG file gives others.
I don't understand these trial days, where they are written in the log file or in the macro itself?
I also can't understand, these words at the beginning and at the end - should they always be contained and numbers should be inserted between them?
In the description in the macro he gave examples, which number is equal to what, but the actually ready code (for continuation of the workbook or a new trial period) in the code - no number matches.
I am asking you for some clarification, I am only begging for that.
I am also posting the last code I am talking about and the link to the official page.
Thank you all for your cooperation.
Setting a Trial Period / Timer for Software Solutions | Experts Exchange
VBA Code:
Private Sub Workbook_Open()
Dim StartTime#, CurrentTime#
Dim TrialPeriod, NewStartTime, NewTrialPeriod
Dim ContKey As String
Dim sh As Worksheet
Dim rStartTime As Range
Dim rTrialPeriod As Range
Dim rKeyList As Range
'********ADDED*********
' Dim UsedKey As String
Dim KeyList As String
Dim KeyOk As Boolean
KeyOk = True
'*********************
Set sh = Sheets("Log") 'This sheet is very hidden
Set rStartTime = sh.Range("StartTime") '(Range A2 of Log sheet)
Set rTrialPeriod = sh.Range("TrialPeriod") '(Range B2 of Log sheet)
Set rKeyList = sh.Range("KeyList") '(Range C2 of Log sheet)
'*****************************************
'SET YOUR OWN TRIAL PERIOD BELOW
'Integers (1, 2, 3,...etc) = number of days use
'1/24 = 1Hr, 1/48 = 30Mins, 1/144 = 10Mins use
TrialPeriod = 15 '< 15 days trial
'If no start time exists then enter the start time and
'the trial period set above into hidden sheet and exit sub
If rStartTime.Value = "" Then
rStartTime.Value = Format(Now, "#0.#########0")
rTrialPeriod = TrialPeriod
MsgBox "Thank you for trying this software"
ThisWorkbook.Save
Exit Sub
Else 'If start time does exist, get the start time and the trial period from the hidden sheet
StartTime = rStartTime.Value
TrialPeriod = rTrialPeriod.Value
End If
CurrentTime = Format(Now, "#0.#########0")
'If not past trial perid then exit sub
If CurrentTime < StartTime + TrialPeriod Then
Exit Sub
End If
'If A1 <> Expired
If [A1] <> "Expired" Then
'Input box for option of entering a key
ContKey = InputBox("Sorry, your trial period has expired. If you " & _
"have a key, enter it now, otherwise your data will be extracted and " & _
"saved for you..." & vbNewLine & "This workbook will then be made unusable until you purchase a key.")
'Check list of already used keys to see if key has been used before. If it has then set
'KeyOk to False (it's set to true at the beginning of this sub
Do Until rKeyList.Value = ""
If rKeyList.Value = ContKey Then KeyOk = False
Set rKeyList = rKeyList.Offset(1, 0)
Loop
Set rKeyList = sh.Range("KeyList")
If KeyOk = False Then
MsgBox "Sorry, that is not a valid key. You can try again after you purchase a key"
' SaveShtsAsBook
[A1] = "Expired"
ActiveWorkbook.Save
Application.Quit
Exit Sub
End If
'*******************************
'If the key entered into input box does not match a pattern you pick then
'run SaveShtsAsBook and do whatever else you need to do to end your app
'The pattern in this code is the first 5 characters must be
'"w14rt" and the last 7 must be "trbft51" in upper or lower case
If UCase(Left(ContKey, 5)) <> "W14RT" Or UCase(Right(ContKey, 7)) <> "TRBFT51" Then
MsgBox "Sorry, that is not a valid key. You can try again after you purchase a key"
' SaveShtsAsBook
[A1] = "Expired"
ActiveWorkbook.Save
Application.Quit
Exit Sub
Else
'Else if the pattern of the key is ok then retrieve the the data from the middle of the key
'which will be some kind of hidden message to tell how much longer to continue
'the trial. Then open the log file back up and enter the new data
'I will use characters 6, 8, 9, 12, 13, 15, and 17 as the digits to retrieve
'for the trial period (the reason for so many is in case you have a lifetime
'key to give, just make the number really huge so it's like millions of days
'into the future, otherwise use leading zeros for the first however many digits
'you need to. You will pick what to put into those places when for the key that
'gets entered, and that will decide the new trial period. So those characters places
'that I mentioned above will be where you want to have digits that will decide the new
'trial period in the key that you give them. Nobody will know the pattern, or the
'place of the characters to retrieve
NewStartTime = Format(Now, "#0.#########0")
'Make NewTrialPeriod = to the number of days for the extended period
NewTrialPeriod = Val(Mid(ContKey, 6, 1) & Mid(ContKey, 8, 1) & Mid(ContKey, 9, 1) & _
Mid(ContKey, 12, 1) & Mid(ContKey, 13, 1) & Mid(ContKey, 15, 1) & Mid(ContKey, 17, 1))
'Enter the new start time and trial period, then exit sub
rStartTime.Value = NewStartTime
rTrialPeriod.Value = NewTrialPeriod
'Add this key to the list of keys already used
sh.Range("C" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Value = ContKey
[A1].Value = ""
ThisWorkbook.Save
Exit Sub
End If
End If
'If A1 already = "Expired" still offer a chance to enter a key which is almost a duplicate of
'above but with a different message and just quit application if no valid key is entered
If [A1] = "Expired" Then
ContKey = InputBox("Sorry, your trial period has expired. If you " & _
"have a key, enter it now, otherwise this application will end.")
'Check list of already used keys to see if key has been used before. If it has then set
'KeyOk to False (it's set to true at the beginning of this sub
Do Until rKeyList.Value = ""
If rKeyList.Value = ContKey Then KeyOk = False
Set rKeyList = rKeyList.Offset(1, 0)
Loop
Set rKeyList = sh.Range("KeyList")
If KeyOk = False Then
MsgBox "Sorry, that is not a valid key. You can try again after you purchase a key"
Application.Quit
Exit Sub
End If
'If the key pattern is not ok then just bring up message and quit
If UCase(Left(ContKey, 5)) <> "W14RT" Or UCase(Right(ContKey, 7)) <> "TRBFT51" Then
MsgBox "Sorry, that is not a valid key. You can try again after you purchase a key"
Application.Quit
Exit Sub
Else
'key pattern was ok so get the characters just like from above
'and change the start time and trial period on the hidden sheet
NewStartTime = Format(Now, "#0.#########0")
'Make NewTrialPeriod = to the number of days for the extended period
NewTrialPeriod = Val(Mid(ContKey, 6, 1) & Mid(ContKey, 8, 1) & Mid(ContKey, 9, 1) & _
Mid(ContKey, 12, 1) & Mid(ContKey, 13, 1) & Mid(ContKey, 15, 1) & Mid(ContKey, 17, 1))
'Enter the new start time and trial period into the log file, then exit sub
rStartTime = NewStartTime
rTrialPeriod = NewTrialPeriod
'Add this key to the list of keys already used
sh.Range("C" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Value = ContKey
[A1].Value = ""
ThisWorkbook.Save
Exit Sub
End If
End If
'Now at this point if a valid key is entered, then the trial period should be extended whatever
'lenght of time was decided from the digits that I mentioned above...
'so for example...if you were to send someone a key to extend the period 30 days, it would be a key
'something like this: W14RT0M00BH007390TRBFT51
'First 5 have to be w14rt, and last 7 have to be trbft51 (in upper or lower case, doesn't matter) to
'match the pattern for a key you would give someone
'The code retrieves digits 6, 8, 9, 12, 13, 15 and 17 to get the trial extension time
'6, 8, 9, 12, and 13 are zeros, 15 is a 3, and 17 is a zero to end up with 0000030
End Sub