Skip to content

Instantly share code, notes, and snippets.

@ScottDeLuzio
Created February 18, 2016 22:33
Show Gist options
  • Save ScottDeLuzio/fb2f05eca14e042bf1dc to your computer and use it in GitHub Desktop.
Save ScottDeLuzio/fb2f05eca14e042bf1dc to your computer and use it in GitHub Desktop.
Software Licensing for Excel Add-In UserForm Activate
Private Sub LicenseKeyActivate_Click()
'license.Value is what the user entered into the text box on the UserForm.
If license.Value = "" Then
MsgBox "Please enter a license key.", vbExclamation, "Input Data"
Exit Sub
Else
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Sheet1").Range("A1")
.Cells(1, 1).Value = license.Value
End With
ThisWorkbook.Save
httpRequestActivate
Unload Me
Application.ScreenUpdating = True
httpRequestCheck
If ThisWorkbook.Worksheets("Sheet1").Cells(5, 1).Value = "in_use" Then
MsgBox "This license key is already in use. Please use another key or deactivate it on the other computer where it is being used."
'You should call a function to hide or disable your add-in here otherwise it can still be used until the user restarts Excel.
Else
With ThisWorkbook.Worksheets("Sheet1").Range("A1")
If .Cells(3, 1).Value = "valid" And .Cells(4, 1).Value = 0 Then
MsgBox "Your license key has been activated."
'Call your add-in here otherwise the user will need to close and re-open Excel.
Else
MsgBox "Your license key may not have been activated. Please close and restart Excel to re-check your license."
End If
End With
End If
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment