ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Limit use Of Workbook (https://www.excelbanter.com/excel-discussion-misc-queries/18565-limit-use-workbook.html)

GWB Direct

Limit use Of Workbook
 
I would like to send a workbook to a potential client but I would only want
them to be able to use it 2 or 3 times. Is there a way to do this. I am using
Xcel 2003. My operating system is Windows XP.
--
Gary Baker

Dave Peterson

Not reliably. Almost anything you (well, I) would do would be based on macros.

And macros can be disabled or modified. (Project protection for the workbook
can be broken pretty simply.)



GWB Direct wrote:

I would like to send a workbook to a potential client but I would only want
them to be able to use it 2 or 3 times. Is there a way to do this. I am using
Xcel 2003. My operating system is Windows XP.
--
Gary Baker


--

Dave Peterson

GWB Direct

Most of my clients don't have the qualifications to diabled or modify a
macro. Could you direct me as to how it can be done. Is there a help screen
in Microsoft that would show me how to create that type of macro.
Thanks for you assistance so far.

"Dave Peterson" wrote:

Not reliably. Almost anything you (well, I) would do would be based on macros.

And macros can be disabled or modified. (Project protection for the workbook
can be broken pretty simply.)



GWB Direct wrote:

I would like to send a workbook to a potential client but I would only want
them to be able to use it 2 or 3 times. Is there a way to do this. I am using
Xcel 2003. My operating system is Windows XP.
--
Gary Baker


--

Dave Peterson


Bob Phillips

No there isn't.

You could do something like this

Const MaxRuns = 3

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If cRuns <= MaxRuns Then
ThisWorkbook.Names.Add Name:="_RunLimit", RefersTo:=cRuns
End If
End Sub

Private Sub Workbook_Open()
Dim cRuns As Long
On Error Resume Next
cRuns = Evaluate(ActiveWorkbook.Names("_RunLimit").RefersT o)
cRuns = cRuns + 1
If cRuns MaxRuns Then
ThisWorkbook.Close savechanges:=False
End If
End Sub

which goes in the ThisWorkbook code module.

--
HTH

Bob Phillips

"GWB Direct" wrote in message
...
Most of my clients don't have the qualifications to diabled or modify a
macro. Could you direct me as to how it can be done. Is there a help

screen
in Microsoft that would show me how to create that type of macro.
Thanks for you assistance so far.

"Dave Peterson" wrote:

Not reliably. Almost anything you (well, I) would do would be based on

macros.

And macros can be disabled or modified. (Project protection for the

workbook
can be broken pretty simply.)



GWB Direct wrote:

I would like to send a workbook to a potential client but I would only

want
them to be able to use it 2 or 3 times. Is there a way to do this. I

am using
Xcel 2003. My operating system is Windows XP.
--
Gary Baker


--

Dave Peterson




Dave Peterson

Bob's suggestion works if the workbook is going to be saved. But if the
workbook isn't saved, then the limit will never be reached.

You could store that counter in the windows registry (but anyone could look to
find this, too).

And that means that each user of the workbook would get 3 times where they could
open the workbook.

Option Explicit
Private Sub Workbook_Open()
Dim myApplication As String
Dim mySection As String
Dim myKey As String
Dim myMax As Long
Dim myCounter As Long
Dim myDefault As Long

myApplication = "MyTestProgram"
mySection = "MyKeys"
myKey = "MyCounter"
myDefault = 0
myMax = 3

myCounter = GetSetting(myApplication, mySection, myKey, myDefault)

If myCounter = myMax Then
MsgBox "This workbook must close"
Me.Close savechanges:=False
Else
SaveSetting myApplication, mySection, myKey, myCounter + 1
End If
End Sub


Again, if macros are disabled (or if the workbook_open/auto_open subs are turned
off), then this won't work either.

And remember to protect the project so that the casual user can't change that
number.

Inside the VBE, Tools|VBAProject Properties|Protection tab.

And that protection is pretty weak, too.

By the way, if you're testing and you want to clean up this testing, you can do
this:

Open excel
hit alt-f11 to view the VBE
hit ctrl-g to view the immediate window
Type this and hit enter:
DeleteSetting "MyTestProgram"

(use the same key as you used in the workbook_open event.

<yep, anyone who can find this post in Google, can do it, too.

GWB Direct wrote:

Most of my clients don't have the qualifications to diabled or modify a
macro. Could you direct me as to how it can be done. Is there a help screen
in Microsoft that would show me how to create that type of macro.
Thanks for you assistance so far.

"Dave Peterson" wrote:

Not reliably. Almost anything you (well, I) would do would be based on macros.

And macros can be disabled or modified. (Project protection for the workbook
can be broken pretty simply.)



GWB Direct wrote:

I would like to send a workbook to a potential client but I would only want
them to be able to use it 2 or 3 times. Is there a way to do this. I am using
Xcel 2003. My operating system is Windows XP.
--
Gary Baker


--

Dave Peterson


--

Dave Peterson

GWB Direct

I can't get this to work. Where it says add names in the code do I put the
name of the workbook. I use macros but I'm not an expert as you can probably
tell.
Thanks in advance for you assistance.
--
Gary Baker


"Bob Phillips" wrote:

No there isn't.

You could do something like this

Const MaxRuns = 3

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If cRuns <= MaxRuns Then
ThisWorkbook.Names.Add Name:="_RunLimit", RefersTo:=cRuns
End If
End Sub

Private Sub Workbook_Open()
Dim cRuns As Long
On Error Resume Next
cRuns = Evaluate(ActiveWorkbook.Names("_RunLimit").RefersT o)
cRuns = cRuns + 1
If cRuns MaxRuns Then
ThisWorkbook.Close savechanges:=False
End If
End Sub

which goes in the ThisWorkbook code module.

--
HTH

Bob Phillips

"GWB Direct" wrote in message
...
Most of my clients don't have the qualifications to diabled or modify a
macro. Could you direct me as to how it can be done. Is there a help

screen
in Microsoft that would show me how to create that type of macro.
Thanks for you assistance so far.

"Dave Peterson" wrote:

Not reliably. Almost anything you (well, I) would do would be based on

macros.

And macros can be disabled or modified. (Project protection for the

workbook
can be broken pretty simply.)



GWB Direct wrote:

I would like to send a workbook to a potential client but I would only

want
them to be able to use it 2 or 3 times. Is there a way to do this. I

am using
Xcel 2003. My operating system is Windows XP.
--
Gary Baker

--

Dave Peterson





GWB Direct

Thanks Dave. Although this may not be the perfect solution, it's better than
nothing.
I appreciate your time and assistance. Hope ypu don't mind but I will
probably have other questions after I attempt to use this code.
--
Gary Baker


"Dave Peterson" wrote:

Bob's suggestion works if the workbook is going to be saved. But if the
workbook isn't saved, then the limit will never be reached.

You could store that counter in the windows registry (but anyone could look to
find this, too).

And that means that each user of the workbook would get 3 times where they could
open the workbook.

Option Explicit
Private Sub Workbook_Open()
Dim myApplication As String
Dim mySection As String
Dim myKey As String
Dim myMax As Long
Dim myCounter As Long
Dim myDefault As Long

myApplication = "MyTestProgram"
mySection = "MyKeys"
myKey = "MyCounter"
myDefault = 0
myMax = 3

myCounter = GetSetting(myApplication, mySection, myKey, myDefault)

If myCounter = myMax Then
MsgBox "This workbook must close"
Me.Close savechanges:=False
Else
SaveSetting myApplication, mySection, myKey, myCounter + 1
End If
End Sub


Again, if macros are disabled (or if the workbook_open/auto_open subs are turned
off), then this won't work either.

And remember to protect the project so that the casual user can't change that
number.

Inside the VBE, Tools|VBAProject Properties|Protection tab.

And that protection is pretty weak, too.

By the way, if you're testing and you want to clean up this testing, you can do
this:

Open excel
hit alt-f11 to view the VBE
hit ctrl-g to view the immediate window
Type this and hit enter:
DeleteSetting "MyTestProgram"

(use the same key as you used in the workbook_open event.

<yep, anyone who can find this post in Google, can do it, too.

GWB Direct wrote:

Most of my clients don't have the qualifications to diabled or modify a
macro. Could you direct me as to how it can be done. Is there a help screen
in Microsoft that would show me how to create that type of macro.
Thanks for you assistance so far.

"Dave Peterson" wrote:

Not reliably. Almost anything you (well, I) would do would be based on macros.

And macros can be disabled or modified. (Project protection for the workbook
can be broken pretty simply.)



GWB Direct wrote:

I would like to send a workbook to a potential client but I would only want
them to be able to use it 2 or 3 times. Is there a way to do this. I am using
Xcel 2003. My operating system is Windows XP.
--
Gary Baker

--

Dave Peterson


--

Dave Peterson



All times are GMT +1. The time now is 07:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com