insert picture with protection

T

tjtjjtjt

I was able to use the Macro Recorder to create a macro that will insert a specific graphic into a text form field in Word 2003 when the macro is called froma Toolbar Button. This is great, except I would like to be able to pick from one of several pictures.
From a previous post by Jay Freedman (thanks, Jay), I found the following code for launching the Insert|Picture Dialog box:
Dialogs(wdDialogInsertPicture).Show

But, since this Command is unavailable while Protection is turned on, the Macro won't work.
Does anyone know of a workaround? Or should I resign myslef to working with Section Breaks?
Thanks,

tj
 
J

Jay Freedman

Hi tj,

Although the command isn't available while protection is turned on, nothing
says the protection has to stay turned on throughout the macro. :) Try
this:

Sub InsPic()
Dim ProtType As WdProtectionType

If Selection.FormFields.Count > 0 Then
' not a textbox but a checkbox or dropdown
' see http://www.word.mvps.org/faqs/tblsfldsfms/GetCurFmFldName.htm
Exit Sub
End If

ProtType = ActiveDocument.ProtectionType
If ProtType <> wdNoProtection Then
ActiveDocument.Unprotect
End If

Dialogs(wdDialogInsertPicture).Show

ActiveDocument.Protect Type:=ProtType, _
NoReset:=True
End Sub

Since the cursor will be inside a form field when the macro starts, and the
..Show method inserts the picture at the cursor, you get a picture inside a
form field -- but only if it's a text box form field, not a checkbox or a
dropdown (those would be completely replaced by the picture).
 
A

Alex Ivanov

NoReset will preserve the form fields data

ActiveDocument.Unprotect "password"
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True,
Password:="password"


--
Please reply to NG only. The email address is not monitored.

Alex.

tjtjjtjt said:
It didn't work with the password. This is not a big deal, as there wasn't
a pasword to begin with...I was jsut curious if there was a way to
accommodate the password without resetting the form when the protection was
reset.
 
T

tjtjjtjt

Thanks!

tj

Alex Ivanov said:
NoReset will preserve the form fields data

ActiveDocument.Unprotect "password"
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True,
Password:="password"


--
Please reply to NG only. The email address is not monitored.

Alex.


a pasword to begin with...I was jsut curious if there was a way to
accommodate the password without resetting the form when the protection was
reset.
 

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