How do I run a macro exiting a field while the form is protected .

C

Colin4

Word 2003
My macros do not work when triggered by exiting a field while my form is
protected.
 
G

Graham Mayor

It depends what the macro does whether it will work or not. Some functions
are only available when the form is unlocked, so your code needs to unlock
and relock the form eg

Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If

'do your stuff

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

Colin4

Graham - thank you for your extreemly prompt response - I will try your
solution this week - thanks again!
 
G

Graham Mayor

You are welcome :)
Note that if the form is password protected you will have to supply the
password between the quotes at both places. The macro as written assumes no
password.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top