Forced Exit of Workbook

Billm

Board Regular
Joined
Mar 19, 2002
Messages
88
I want to put some sort of warning message or window to the user when the workbook opens confirming that they have an authorised copy of my workbook. If they press NO, then I want the workbook to close down without saving any changes.

This is just a simple "copyright protection" check I am trying to install to deter people from making illegal copies and distributing it.

Any other ideas in this area would also be appreciated.
Thanks
Bill
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi,

You can use a simple piece of VBA code. Right click the lower of the two Excel icons on the top left hand of your screen and choose View Code. Paste this:-

Code:
Private Sub Workbook_Open()
If MsgBox("Do you have an authorised copy of this workbook?", vbYesNo + vbQuestion, _
            "Authorisation Check") = vbNo Then Me.Close False
End Sub

How's that?
 
Upvote 0
In addition to this, is there a way that I can say run a macro that will store the licenced users name and email address in a VBA variable permanently ?

I could run this when I licence the product originally. Then when the workbook opens up, I can display those details in the above MessageBox.

Storing the details in a sheet cell would be too easy to spot and change hence why I would prefer a VBA variable or constant.

Thanks
Bill
 
Upvote 0
On 2002-10-21 06:34, Billm wrote:
In addition to this, is there a way that I can say run a macro that will store the licenced users name and email address in a VBA variable permanently ?

I could run this when I licence the product originally. Then when the workbook opens up, I can display those details in the above MessageBox.

Storing the details in a sheet cell would be too easy to spot and change hence why I would prefer a VBA variable or constant.

Thanks
Bill

Hi,

You can't use a normal variable because the variable will be reset to zero or "" as soon as it goes out of scope i.e. the workbook is closed. You can create a custom property though which is saved with the workbook e.g.

ThisWorkbook.CustomDocumentProperties.Add Name:="UserID", LinkToContent:=False, _
Type:=msoPropertyTypeString, Value:="Dan, dan@acme.com"
 
Upvote 0
Dan
that looks like it will do the job. I have run the code from a macro, which should have set it, exited the workbook and now want to look it up when I run the sub Workbook_Open to test its value.

How do I lookup that UserID value once its been stored ?

Also, I just re-ran your code again from the macro and I now get a run-time error. Can it only be run once or something ie it can't over-write that variable value?

Thanks
Bill
 
Upvote 0

Forum statistics

Threads
1,214,627
Messages
6,120,610
Members
448,973
Latest member
ChristineC

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