View Single Post
  #5   Report Post  
Dave Peterson
 
Posts: n/a
Default

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