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!! :eek2:
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!! :bigyello:
Thanks so much for your help! :duck: (I don't know... I just like the duck!!) :D
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:
ActiveDocument.Protect Password:="", NoReset:=False, Type:= _
wdAllowOnlyFormFields
to protect document for forms
VB Code:
ActiveDocument.Unprotect Password:=""
pete
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:
Sub ProtectDoc()
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If
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)?
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