Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Page Layout / July 2007

Tip: Looking for answers? Try searching our database.

Setting up protected document that can insert  picture (photo ID template)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Craig - 11 May 2004 20:13 GMT
Cannot find a way to insert picture from file with
document protected. We have an inhouse design department
and are attempting to create Photo ID templates that a
user can insert pictures and text with the document
protected. The text works great but to save my life I
cannot figure out how to insert a picture while the
document is protected.
Jay Freedman - 11 May 2004 21:00 GMT
Hi Craig

Word doesn't have a form field that can hold a picture. There is a
workaround, though. With a macro you can unprotect the document momentarily,
insert the picture, and reprotect the document.

First copy/paste this macro into a module of the template (see
http://www.gmayor.com/installing_macro.htm):

Public Sub ProtectedInsertPicture()
  Dim ilsPicture As InlineShape
  Dim strFileName As String
  Dim sngRatio As Single
  Const max_width = 216   ' = 3 inches (in points)

  ' temporarily unprotect
  ActiveDocument.Unprotect

  ' show Insert Picture dialog
  With Dialogs(wdDialogInsertPicture)
     If .Display = 0 Then Exit Sub
     strFileName = .Name
  End With

  ' remove macrobutton
  Selection.Delete

  Set ilsPicture = ActiveDocument.InlineShapes _
        .AddPicture( _
        FileName:=strFileName, _
        LinkToFile:=False, _
        SaveWithDocument:=True, _
        Range:=Selection.Range)

  ' limit size of picture to max_width (optional)
  With ilsPicture
     If .Width > max_width Then
        sngRatio = CSng(max_width) / .Width
        .Width = max_width
        .Height = .Height * sngRatio
     End If
  End With

  ' reprotect, keeping form field contents intact
  ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
     NoReset:=True
End Sub

Then insert a MacroButton field at each place where the user should be able
to insert a picture, using the field code

{ MacroButton ProtectedInsertPicture Double-click to add picture }

You can use font, border, and shading formatting to make the "Double-click"
part look like a rectangula button. Press Ctrl+A and then F9 to update the
fields. Protect and save the template.

When the user creates a new form from the template and fills it in, s/he can
double-click the "button" even though it's in a protected area of the
document. The macro will unprotect, pop up the Insert > Picture > From File
dialog, insert the picture (replacing the macrobutton), and reprotect. The
optional section of the macro will resize the picture if it's wider than the
number of points you assign to max_width -- if you don't need that, just
delete the section of code between With ilsPicture and End With.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Cannot find a way to insert picture from file with
> document protected. We have an inhouse design department
[quoted text clipped - 3 lines]
> cannot figure out how to insert a picture while the
> document is protected.
Jay Freedman - 11 May 2004 21:10 GMT
Oops, missed a bit. If the user cancels out of the Insert Picture dialog,
the macro leaves the document unprotected. This fixes it:

  ' show Insert Picture dialog
  With Dialogs(wdDialogInsertPicture)
     If .Display = 0 Then
        ActiveDocument.Protect _
           Type:=wdAllowOnlyFormFields, _
           NoReset:=True
        Exit Sub
     End If
     strFileName = .Name
  End With

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hi Craig
>
[quoted text clipped - 69 lines]
>> cannot figure out how to insert a picture while the
>> document is protected.
Craig - 12 May 2004 15:43 GMT
Amazing workaround! Thank you very much for taking the
time to help - It works wonderfully. . I have been
struggling with this issue for a while and this is a
great solution.

Is there any way to give the user a chance to re-insert a
picture (in the case that they select the wrong file or
just need to modify it.

THANK YOU!!!

Craig

>-----Original Message-----
>Oops, missed a bit. If the user cancels out of the Insert Picture dialog,
[quoted text clipped - 86 lines]
>
>.
Jay Freedman - 13 May 2004 02:27 GMT
Hi Craig

Replacing the picture gets a bit fiddly, especially as the macrobutton
isn't there any more to rerun the macro. I'll give that one a bit more
thought. It should be possible to make the picture replace just the
display text inside the macro code, so the picture itself becomes the
"button" for next time. I need to play with it to make sure it doesn't
head off into Never-Never-Land.

What version(s) of Word does this have to work with? It may make a
difference.

In the meantime, you could (a) use Tools > Unprotect Document, (b)
manually delete the old picture and insert the new one, and (c)
reprotect. In most versions of Word you have to use a macro to
reprotect, because using Tools > Protect Document from the menu will
clear all the text form fields. See
http://word.mvps.org/FAQs/MacrosVBA/TurnFmFlfResetOff.htm for that.

>Amazing workaround! Thank you very much for taking the
>time to help - It works wonderfully. . I have been
[quoted text clipped - 116 lines]
>>>> cannot figure out how to insert a picture while the
>>>> document is protected.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://www.mvps.org/word
skylark_za - 13 Jul 2007 13:15 GMT
Hi

I am unable to run this macro 100% correctly. It seems to work if I
double click the macro button when the document is unprotected but when
the document is protected, the macro no longer functions at all when
double clicked. The cursor just jumps to the next text form field. Am I
doing something wrong when applying this macro or when I am executing
it?

I copied and added you macro as it appears below.

Public Sub ProtectedInsertPicture()
Dim ilsPicture As InlineShape
Dim strFileName As String
Dim sngRatio As Single
Const max_width = 216   ' = 3 inches (in points)

' temporarily unprotect
ActiveDocument.Unprotect

' show Insert Picture dialog
With Dialogs(wdDialogInsertPicture)
If .Display = 0 Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True
Exit Sub
End If
strFileName = .Name
End With

' remove macrobutton
Selection.Delete

Set ilsPicture = ActiveDocument.InlineShapes _
AddPicture( _
FileName:=strFileName, _
LinkToFile:=False, _
SaveWithDocument:=True, _
Range:=Selection.Range)

' limit size of picture to max_width (optional)
With ilsPicture
If .Width > max_width Then
sngRatio = CSng(max_width) / .Width
Width = max_width
Height = .Height * sngRatio
End If
End With

' reprotect, keeping form field contents intact
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End Sub

Regards

Jason

Signature

skylark_za


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.