Results 1 to 4 of 4

Thread: Help!! Attempting to Protect Document in Word using VB, but only after pre-requisite

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    2

    Exclamation Help!! Attempting to Protect Document in Word using VB, but only after pre-requisite

    Hi all,

    Thanks heaps for reading! They need an icon of a little face ripping its hair out for this one!!

    Okay - here goes.

    I'm attempting to write (very amateury type beginner speaking here...) some code in Visual Basic to protect a word template (so that my form will work!). My problem is that before the protection can come into effect, there are some fields that load automatically (via an interface with an external system) because if the template is protected straight away then these fields will not import.

    Help? Ideally, what I want is for the template to open, the fields to import, then the document to lock so that form fields work correctly - all without manual intervention....

    Any idea's welcome!!

    Oh... and since I'm such an amateur example code would be a plus!!

    Thanks so much for your help! (I don't know... I just like the duck!!)
    Last edited by zeedart; Jul 6th, 2006 at 10:11 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help!! Attempting to Protect Document in Word using VB, but only after pre-requisite

    you could have the template protected, then on document open run a macro to unprotect, update the field and set protection again

    VB Code:
    1. ActiveDocument.Protect Password:="", NoReset:=False, Type:= _
    2.         wdAllowOnlyFormFields
    to protect document for forms

    VB Code:
    1. ActiveDocument.Unprotect Password:=""


    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    2

    Question Re: Help!! Attempting to Protect Document in Word using VB, but only after pre-requis

    Thanks for your input Pete - here's the script I have written at the moment:

    VB Code:
    1. Sub ProtectDoc()
    2. If ActiveDocument.ProtectionType = wdNoProtection Then
    3. ActiveDocument.Protect _
    4. Type:=wdAllowOnlyFormFields, NoReset:=True
    5. End If
    6. End Sub


    My problem is that I want this to activate about 8 seconds after the person opens the document. (The document is unprotected upon opening)... how do I do this (with no manual intervention)?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help!! Attempting to Protect Document in Word using VB, but only after pre-requisite

    put your code into the "this document" open sub

    if need be put a loop to detect when whatever you are waiting for has finished, then protect

    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width