Enabling macros in a form

P

Philippe

Hello,
I'musing Word 2007 but saving in 2003 format to allow for compatibility
across the company.
I've created a document with multiple sections. One section is a form that
limits user's input. The other section is open to editing.
I have also created macros that allow users to do some specific formatting
in the editing section.
What I am finding out is that once I protect the document the macros are
disabled.
How can I have the best of both world: form and macro?
Thanks in advance.
 
C

covingj

I had a similar problem with an Excel workbook, and the issue was the macro
security on the end user's machines. They have to be able to allow the macro
to run, which means they have to know the dialog appears right under the
ribbon, as opposed to being a stand alone dialog box that pops up when they
open the file. I am sure that the phenomenally intelligent individuals who
inhabit this board may be able to come up with a more elegant solution, but
just in case I wanted to share my experience. (And yes, I recognize this is a
Word forum, but aren’t these Office products supposed to act in a similar
fashion to each other?)
 
G

Graham Mayor

My first observation is that a protected form is for collecting data and is
rarely the correct vehicle for a document that requires free editing. For
that you should collect the data in a userform and apply it to docvariables
which may be inserted in the document using docvariable fields. For the
basics, see Word MVP FAQ - Userforms
http://word.mvps.org/FAQs/Userforms.htm

for a more in depth explanation, see
http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm

However what you want to do is achievable. You simply have to include in
your macro the code to unlock the form, perform the task then re-lock it
again.


Dim i As Integer
Dim bProtected As Boolean
Dim sPassword As String
sPassword = "" 'The password to unlock the form
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=sPassword
End If

'do what you want with the document here

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


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
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