Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Nov 2003
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Forms-Lock Macro (2000)

    I want to set up a macro to lock my form in word. Can someone please give me the script?

    Also I find if I use the protect icon and toggle it on and off (so I can insert some graphics into the document), if I unprotect the document, insert the graphics, then protect the document, it reverts back to the original form and all my changes are deleted. We have set up a form template for our users for them to write their own procedure protocols, but when they need to add graphics I run into the problem as described above. Is there a work around?

    Thanks

    Jac

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Forms-Lock Macro (2000)

    Here is a macro I use. It doesn't clear form fields when re-protecting. See if it works for you (it seems to work OK with graphics, but I haven't tested that extensively.) If you use a password, add that to both the Protect and Unprotect statements.

    Sub SafeProtectToggle()
    ' Toggle protection for forms without losing form field results
    On Error Resume Next
    If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
    ActiveDocument.Unprotect
    Else
    ActiveDocument.Protect wdAllowOnlyFormFields, True
    End If
    End Sub

  3. #3
    New Lounger
    Join Date
    Nov 2003
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms-Lock Macro (2000)

    Thanks HansV for your prompt advice. Works wonderfully! You guys always get it right!!!!

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms-Lock Macro (2000)

    Hi Hans:
    Out of curiosity, how does Word know that

    ActiveDocument.Protect wdAllowOnlyFormFields, True
    is the equivalent of
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
    Thanks,
    (I know, I should learn some basic VBA by now) <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Forms-Lock Macro (2000)

    I think I can take this one. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> It doesn't! By default, the functions and methods take arguments in a strictly prescribed order which is documented in the help files. However, Visual Basic lets you feed them to the function/method in any order you want by using "named arguments." (Note that VBScript doesn't support named arguments, even when targeting the same objects.)

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms-Lock Macro (2000)

    Thanks, Jefferson. Then I take it that both wdAllowOnlyFormFields and True are both named arguments.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Forms-Lock Macro (2000)

    Almost, but not quite. You can look up the syntax of the Protect method in the Visual Basic Editor by activating the Object Browser (F2 is the shortcut key), typing protect in the search box and pressing Enter.
    <hr>Sub Protect(Type As WdProtectionType, [NoReset], [Password])<hr>
    The named arguments of the Protect method are Type, NoReset, and Password (the latter is not used in the example in this thread.) The square brackets around NoReset and Password mean that they are optional arguments, they may be omitted. There are no square brackets around Type, so Type is a required argument.

    Type can have one of four values:
    - wdAllowOnlyComments
    - wdAllowOnlyFormFields
    - wdAllowOnlyRevisions
    - wdNoProtection

    NoReset is a Boolean (True or False), and Password is a string.

    The following statements are equivalent:

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
    ActiveDocument.Protect wdAllowOnlyFormFields, True

    but the following is incorrect because the arguments are neither named, nor in the correct order.

    ActiveDocument.Protect True, wdAllowOnlyFormFields

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Forms-Lock Macro (2000)

    What he said. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    wdAllowOnlyFormFields is a constant, a mnemonic way to refer to a numeric value. If you were to open the object browser (F2 in the VBE) and find wdAllowOnlyFormFields, the numeric value would show in the bottom pane. Or enter

    ?wdAllowOnlyFormFields

    in the Immediate Window (Ctrl+G) for a quick translation. There are times when you have to use the numeric values, for example, if you invoke ADO in an ASP page without referencing the type library, then VBScript can't translate the ADO constants and the page will give you errors. Such fun, isn't it?!

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms-Lock Macro (2000)

    Thanks to both of you. I really have to find some time to learn this stuff. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

Posting Permissions

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