Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Nov 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Forms (Word 2003)

    Hi: I have a word form that is protected. I have several text fields on the form. I would like to do a copy of more than one text field at a time. Is there a macro that would allow this to happen without my users having to manually unprotect the file.
    Thank you!

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

    Re: Word Forms (Word 2003)

    You can unprotect the document in the macro, perform whatever actions you need, then re-protect the document without resetting the form fields:
    <code>
    Sub Test()
    On Error GoTo ErrHandler
    ' Unprotect
    ActiveDocument.Unprotect
    ' Your code goes here
    ...
    ...

    ExitHandler:
    ' Re-protect
    On Error Resume Next
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub
    </code>
    I added an error handler to ensure that the document ends up protected again even if an error occurs.

  3. #3
    New Lounger
    Join Date
    Nov 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Forms (Word 2003)

    Tried this code. It only highlights one form field at a time. I would like to select a section. See example file. I need this to select from Context to Procedures form fields together. (see macro at top of doc)
    Thank you!
    Attached Files Attached Files

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

    Re: Word Forms (Word 2003)

    Do you mean the CopyPaste macro at the bottom of the module? You haven't added anything to the macro I posted, so it doesn't do anything.

    You could do the following (you only need to do it once):
    - While the document is unprotected, select the text from Context up to and including the Procedures formfield.
    - Select Insert | Bookmark...
    - Specify a name, for example MyRange, then click Add.
    - Protect the document.

    The macro could then look like this:

    Sub CopyPaste()
    On Error GoTo ErrHandler
    ' Unprotect
    ActiveDocument.Unprotect
    ' Copy text of bookmark
    ActiveDocument.Bookmarks("MyRange").Range.Copy

    ExitHandler:
    ' Re-protect
    On Error Resume Next
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

    This copies the contents of the bookmark to the clipboard, ready to be pasted elsewhere.

  5. #5
    New Lounger
    Join Date
    Nov 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Forms (Word 2003)

    I have a form with text fields.
    Name: ________ (text1)

    Address: ________(text2)

    This document is protected and I set a bookmark to highlight my two input fields so that I can copy them to another location. I wrote the following code but when I execute the macro it does not highlight the two text fields only one. Could I get assistance with my code highlighting "MyRange" which consists of Text1 & Text2.

    Sub CopyDoc()
    On Error GoTo ErrHandler
    ' Unprotect
    ActiveDocument.Unprotect
    ' Copy text of bookmark
    ActiveDocument.Bookmarks("MyRange").Range.Copy

    ExitHandler:
    ' Re-protect
    On Error Resume Next
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub


    Thanks

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

    Re: Word Forms (Word 2003)

    The code doesn't select the bookmark. It doesn't need to. Instead, it copies the contents of the bookmark to the clipboard, ready to be pasted elsewhere.
    If you don't get the text you expected when you paste, the most probable explanation is that the bookmark MyRange hasn't been defined correctly. Check this carefully, or create the bookmark anew.

Posting Permissions

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