Microsoft Office Tutorials and References
In Depth Information
Forms: Placing a Picture in a Protected Form
'Display the Insert picture dialog box¶
'But don't let it execute¶
Set dlg = Dialogs(wdDialogInsertPicture)¶
'If cancel was not clicked¶
If dlg.Display <> 0 Then¶
'Make sure the target exists¶
If doc.Bookmarks.Exists(BookmarkTarget) Then¶
Set rng = doc.Bookmarks(BookmarkTarget).Range¶
'Delete any pictures currently in the bookmark¶
If rng.InlineShapes.Count > 0 Then¶
'Insert the picture into the bookmark¶
Set ils = doc.InlineShapes.AddPicture( _¶
FileName:=dlg.Name, LinkToFile:=False, _¶
'Recreate the bookmark around the picture¶
doc.Bookmarks.Add Name:=BookmarkTarget, _¶
'MsgBox "Target for picture not found"¶
doc.Protect Type:=wdAllowOnlyFormFields, _¶
Set the constant values:
If the form is protected with a password, supply it here.
The macro must temporarily unprotect the form in
order to delete the row. If no password has been
assigned, use a zero-length string ("").
The name of the bookmark marking the target position
for the picture being inserted.
The macro runs from a toolbar that displays when a document is created using
Set up the form. Insert a bookmark at each location where the user should be
able to insert a picture.