Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Sep 2002
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    run macro a couple of times without registration (Word)

    Could someone help me with a bit of code that will only
    allow my MS Word macro to run 5 times before requiring a
    registration number.

    I was thinking of maybe a window poping up saying this if
    the 3rd time it has been used would they like to register?
    or something like that. And then don't let it work without
    a registration number

    Once they have a registration number this box wouldn't
    show up and the Macro will just run.

    Is this something someone could help me with?

    many thanks
    Richi

  2. #2
    2 Star Lounger
    Join Date
    Jul 2001
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run macro a couple of times without registration (Word)

    This is a starting point for you.....

    Sub YOUR_SUB_NAME()

    'Check to see how many times the macro has been used
    Used_counter = GetSetting(appname:="YOUR_APP_NAME", section:="Registration", Key:="COUNTER")

    'Check to see if the program has been registered
    registered = GetSetting(appname:="YOUR_APP_NAME", section:="Registration", Key:="registered")


    If Used_counter < 5 or registered = "true" Then

    'THIS SECTION ALLOWS THE USER TO USE THE MACRO

    'ALL YOUR CODE



    if registered = "false" then
    Used_counter = Used_counter + 1 'increment your counter
    SaveSetting appname:="YOUR_APP_NAME",section:="Registration",k ey:="counter", setting:=Used_counter
    end if

    Else
    MyCode=inputbox("You must now register")

    if MyCode = "123" then
    msgbox("thanks for registering")
    SaveSetting appname:="YOUR_APP_NAME", section:="Registration",Key:="registered", setting:=True
    Else
    msgbox("incorrect reg code")
    SaveSetting appname:="YOUR_APP_NAME", section:="Registration",Key:="registered", setting:=False
    end if



    End if

    End sub

  3. #3
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run macro a couple of times without registration (Word)

    Besides using the registry another poster mentioned, you can created a named variable which stays with your program. It is initially set to 1 and then each time the workbook is closed, your code increments it by one. So now each time your program iis opened, the "open" code checks if the named variable is = to some maximum value (5 in your case) and if so, then displays message and closes itself.

    The advantage to this over the registry is that it's hidden in the code itself and can't be changed like it can in the registry (thereby letting the user run it more than 5 times). You can have a named var called MaxAllow and then remember to hide this named so that the user can't change it. Here's a sample in Excel but I'm sure you can change this to work on Word as the concept is the same (change Thisworkbook to ThisDocument).
    <pre>Thisworkbook.Names("MaxAllow").Visible = False ' hide your named var, do once after create it

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    if [MaxAllow] > MAX_NUM then
    msgbox "You have exceeded the # of times this application can be used. Please buy it now!"
    application.displayalerts = false
    thisworkbook.saved = true
    thisworkbook.close
    end if
    end sub</pre>

    The square brackets, [ ] around the named var is a shortcut and is only good for constants, not addresses.

    HTH, Deb <img src=/S/pirate.gif border=0 alt=pirate width=22 height=18>

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run macro a couple of times without registration (Word)

    In Word you can use the Variables Collection. THe only down side is that if the end-user doesn't save the document with the code after the variable has been incremented, it doesn't keep the incrementation

    <pre>Private Sub Document_Open()
    Dim doc As Document

    Set doc = ActiveDocument

    On Error Resume Next
    doc.Variables.Add "MaxRuns"

    doc.Variables("MaxRuns") = Val(doc.Variables("MaxRuns")) + 1

    If doc.Variables("MaxRuns") > 5 Then
    MsgBox "Run more than 5 times. Goodbye."
    doc.Close False
    End If

    End Sub</pre>

    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  5. #5
    New Lounger
    Join Date
    Sep 2002
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run macro a couple of times without registration (Word)

    OK guys!

    Thanks for the advice and I will give them all a try tonight.

    A couple of questions though!

    How will the codes you have given me above know what registration number is acceptable?

    As a beginner I am not to sure how to implement this with my other code. Would be grateful for some advice.

    Richi

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run macro a couple of times without registration (Word)

    A simple macro can be run by the user to change the count.

  7. #7
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run macro a couple of times without registration (Word)

    Thanks for the insight on how this works in Word VBA (I only know Excel VBA). In my projects which I need this type of thing, I always force a save at close (which is what my code showed). I figured since this situation was for a trial version of the poster's program, that 'side effect' is just something the user would have to deal with.

    Deb <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

  8. #8
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run macro a couple of times without registration (Word)

    To answer your question ".. what registration # is acceptable?" that's up to you, your'e writing the code. I had used a constant set to 5 which is defined like this:

    Public Const MAX_NUM as Integer = 5

    If you go with the registry solution, the first time you create the registry entry, its value = 1. The next time the document is opened, you read this value and compare it to MAX_NUM. If it's <= then you increment this value (registry value) by one for next time and then just let the user run your program. Keep doing this each tiime your program is opened until the registry value > MAX_NUM and then you know the user has run it more than MAX_NUM tiimes. You then display some message and exit.

    1. First time program is used.
    Write registry entry, set value to 1. Let user run your program.

    2. Next time program is used.
    Read registry entry. If value <= MAX_NUM, increment its value (write it back to registry as value +1), let user run your program.
    If value > MAX_NUM, show message to user, close your program.

    Since I don't know Word VBA like I do Excel, I can only give you pseudo code:

    <pre>At_Document_Open_Do_This
    If Registry_Entry_Exists then
    currentValue = Read_Registry_Entry
    if currentValue > MAX_NUM then
    msgbox "You have run this program too many times, you gotta pay for it now."
    ThisDocument.Close ' or whatever syntax it is in Word to quit/exit
    else
    ' user still has more times to go to run it
    Write_Registry_Entry( currentValue + 1 )
    end if

    ' from here, user runs the program as usual until next time it's opened
    else
    Create_Registry_Entry( 1 ) ' create entry, make value = 1
    end if</pre>


    You write the code for the routines: Registry_Entry_Exists(), Read_Registry_Entry(), Write_Registry_Entry(), Create_Registry_Entry().
    Deb

  9. #9
    New Lounger
    Join Date
    Sep 2002
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run macro a couple of times without registration (Word)

    People I feel like I am hitting a <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15> . As a beginner it is a lot to take in.

    I am getting the dims wrong, errors and all sorts.

    I have posted the macro that I am trying to include it in and maybe someone could show me how to put it together.
    My main concern is learning what is going on so I would be grateful for a short explination if that is not asking too much!
    Thank you again people and i am sure you understand that we all have to begin somewhere. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

    Sub FindHomonyms()
    Dim oRg As Range
    Dim LineFromFile As String, LineString As String
    Dim path As String
    Dim WordArray As Variant
    Dim indx As Integer, LparenPos As Integer, RparenPos As Integer
    Dim WholeDocument As String

    WholeDocument = LCase$(ActiveDocument.Range.Text)

    path = ThisDocument.path
    Open path & Application.PathSeparator & "data.txt" For Input As #1
    Do While Not EOF(1)
    Line Input #1, LineString
    LparenPos = InStr(LineString, "(")
    Do While LparenPos > 0
    RparenPos = InStr(LparenPos, LineString, ")")
    If RparenPos > 0 Then
    LineString = Left(LineString, LparenPos - 2) & _
    Right(LineString, Len(LineString) - RparenPos)
    LparenPos = InStr(LineString, "(")
    End If
    Loop
    LineFromFile = LineFromFile & vbTab & LineString
    Loop
    Close #1

    WordArray = Split(LineFromFile, vbTab)

    Set oRg = ActiveDocument.Range

    Application.ScreenUpdating = False

    With oRg.Find
    .ClearFormatting
    .Replacement.ClearFormatting

    .Replacement.Font.Underline = wdUnderlineWavy

    .Replacement.Text = "^&" ' <= code for "found text"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False

    For indx = 1 To UBound(WordArray)
    If InStr(WholeDocument, LCase$(WordArray(indx))) > 0 Then
    .Text = WordArray(indx)
    .Execute Replace:=wdReplaceAll
    End If
    StatusBar = UBound(WordArray) - indx
    DoEvents
    Next indx
    End With

    Application.ScreenUpdating = True
    End Sub

  10. #10
    New Lounger
    Join Date
    Sep 2002
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: run macro a couple of times without registration (Word)

    Still need some help with this one.
    Many thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •