• 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.

How to create/generate a licence code for my excel file.

akinkaraman

Member
Is there a way to licence an excel file and give a code to users which will expire sometimes later and will ask to renew the licence?
 
You could try something like this.

Code:
Private Sub WorkBook_Open()
Dim edate As Date, mbox As Variant, myuser As String, wbuser As String

Application.ScreenUpdating = False
edate = DateSerial(2015, 2, 25)

If Date > edate Then
    MsgBox "Oops! Test/Evaluation period of the utility has been expired." & vbCrLf & _
            "Pls ask the concern person to get the updated utility.", vbCritical, "Outdated/Expired Version"
    mbox = Application.InputBox("Pls input the password/code to continue...", "Password")
        If mbox <> "ABCD" Then ThisWorkbook.Close False
End If
End Sub
 
Deepak it is excellent. Thank you.

I just want if I hide that macro? Otherwise the password can be seen before expired.
 
Hello Deepak, this method can protect my excel file very good and let me allow people to use sometimes.

Following code directly deletes the file if it is expires.

Can we combine this code with your code?
So it will ask the password, if the password is wrong or close without entering the password then it will kill the file.

Deepak Password Require Code
Code:
Private Sub WorkBook_Open()
Dim edate As Date, mbox As Variant, myuser As String, wbuser As String

Application.ScreenUpdating = False
'CHANGE THE DATE
edate = DateSerial(2015, 2, 21)

If Date > edate Then
    MsgBox "Oops! Test/Evaluation period of the utility has been expired." & vbCrLf & _
            "Pls ask the concern person to get the updated utility.", vbCritical, "Outdated/Expired Version"
    mbox = Application.InputBox("Pls input the password/code to continue...", "Password")
        If mbox <> "ABCD" Then ThisWorkbook.Close False
End If
End Sub

Killing the Expired File Code
Code:
Private Sub WorkBook_Open()
If Date >= CDate("21.02.2015") Then
Application.Quit
With ThisWorkbook
        .Save
        .ChangeFileAccess Mode:=xlReadOnly
        Kill .FullName
        .Close SaveChanges:=False
    End With
End If
End Sub
 
I think I have done..

Code:
Private Sub WorkBook_Open()
If Date > CDate("21.02.2015") Then
MsgBox "Oops! Test/Evaluation period of the utility has been expired." & vbCrLf & _
            "Pls ask the concern person to get the updated utility.", vbCritical, "Outdated/Expired Version"
    mbox = Application.InputBox("Pls input the password/code to continue...", "Password")
End If
        If mbox <> "ABCD" Then
Application.Quit
With ThisWorkbook
        .Save
        .ChangeFileAccess Mode:=xlReadOnly
        Kill .FullName
        .Close SaveChanges:=False
    End With
End If
End Sub
 
Last edited:
What I couldn't understand, when this file is opening in a (new) computer first time and disable the macros, it is working without macros; so the one can see and still use the file without macros.

So how will it protect the file? Can any solution which will block the file without accepting the macros?

Actually what I wanted was the excel file would create a serial code and asks to give the activation code. So the owner of the file would give the activation code to user to reopen the file.

I am very confused.
 
Last edited:
You only make an Introduction worksheet available which prompts them to enable macros, everything else is hidden

If they enable macros unhide a worksheet/s

otherwise they are stuck

Have a read of the technique which is described here:
http://datapigtechnologies.com/blog/index.php/forcing-your-clients-to-enable-macros/

I would modify that to once the Macros are enabled, load a sheet which asks for the password/ registration etc

Then once acceptable, show the rest of the worksheets

For a more specific answer I'd suggest posting the file or at least part of it.

What do you want any registration based on ?
 
Last edited:
Hello Mr. Hui..

I coppied same codes inside my file but I couldn't be succeed. Let me post my sample file.

The password is ABCD
 

Attachments

  • clock.xlsm
    20.8 KB · Views: 105
Last edited:
Wow! You are the big master Mr. Hui. I am admired of you. You should really write a book. I am a big fan of Chandoo forum and all Excel Ninjas here are genius for me.

Mr Hui, I added all my sheets such as Sheets("Sheet").Visible = xlVeryHidden at the beginning and Sheets("Sheet").Visible = True at the end by one by and all of them are hidding now.

Instead of this what else can we do such as show Intro and hide other; Else show others and hide Intro. ??
 
And one problem I faced up now. I change the date to yesterday and now it says it is expired but it doesn't ask password anymore, the Intro page is just opening. And kill the file if entering wrong password is no longer working.
 

Attachments

  • clock.xlsm
    20.4 KB · Views: 41
Sir I've worked on the codes. I think I solved the problem.

Code:
Public MyDate As Variant

Private Sub WorkBook_Open()

MyDate = #2/22/2015#  ' Assign a date.
Application.ScreenUpdating = False
Sheets("Intro").Visible = True
Sheets("Clock").Visible = xlVeryHidden
Application.ScreenUpdating = True

If Date > MyDate Then
MsgBox "Oops! Test/Evaluation period of the utility has been expired." & vbCrLf & _
  "Pls ask the concern person to get the updated utility.", vbCritical, "Outdated/Expired Version"
  mbox = Application.InputBox("Pls input the password/code to continue...", "Password")

  If mbox <> "ABCD" Then
  MsgBox "Incorrect Password" & vbCrLf & _
  "Pls ask the concern person to get the correct password.", vbCritical, "Wrong password"

Application.Quit
With ThisWorkbook
  .Save
  .ChangeFileAccess Mode:=xlReadOnly
  Kill .FullName
  .Close SaveChanges:=False
  End With
Else
  Sheets("Clock").Visible = True
  Sheets("Intro").Visible = False
  End If

End If


End Sub

I am very appreciated..
 

Attachments

  • clock.xlsm
    20.9 KB · Views: 82
Last edited:
Now even I enter the right password it doesn't show my sheet. And when I enter the wrong password it doesn't kill my sheet.

I am working on the code now. :)
 
Last edited:
I have commented out the Kill line so that it doesn't kill the file by accident
Kill deletes the workbook so I hope you are backing it up !
 
Looks like working.. :)

Code:
Public MyDate As Variant
Public Passwd As String

Private Sub WorkBook_Open()

MyDate = #2/22/2015#  ' Assign a date.
Passwd = "ABCD" 'Assign password

Application.ScreenUpdating = False
Sheets("Intro").Visible = True
Sheets("Clock").Visible = xlVeryHidden
Application.ScreenUpdating = True

If Date > MyDate Then
MsgBox "Oops! Test/Evaluation period of the utility has been expired." & vbCrLf & _
  "Pls ask the concern person to get the updated utility.", vbCritical, "Outdated/Expired Version"
  mbox = Application.InputBox("Pls input the password/code to continue...", "Password")

  If mbox <> Passwd Then
  MsgBox "Incorrect Password" & vbCrLf & _
  "Pls ask the concern person to get the correct password.", vbCritical, "Wrong password"

Application.Quit
With ThisWorkbook
  .Save
  .ChangeFileAccess Mode:=xlReadOnly
  Kill .FullName
  .Close SaveChanges:=False
  End With
Else
  Sheets("Clock").Visible = True
  Sheets("Intro").Visible = False
  End If

End If


End Sub
 
Last edited:
I am trying to understand what "Application.ScreenUpdating" does?
In the code it is first False then True


Code:
Application.ScreenUpdating = False
Sheets("Intro").Visible = True
Sheets("Clock").Visible = xlVeryHidden
Application.ScreenUpdating = True
 
Application.ScreenUpdating=False turns off screen updating
Application.ScreenUpdating=True turns on screen updating
So changes in between don't cause the screen to flicker/flash as changes like changing page occur
 
Back
Top