Insert Picture Automation

M

Molly

Hello

I have read through many of the Insert Picture VBA
questions and answers in this site, the MVP site and even
asked google but none seem to answer my question.

I would like to add a button to my users form which will
allow me to choose a picture file (show the insert picture
dialog box), the chosen picture will then be inserted into
the header area of my document.

I would appreciate any guidance. Thank you for your time.

Molly.
 
D

Dave Lett

Hi Molly,

You haven't really provided enough information to provide an iron-clad
result. That is, if you have multiple sections in your document, which
section do you want this picture to appear? How do you want to insert the
picture (as a object or a field)? If you insert the picture as a field, do
you want to save it with the document or not? Is the picture the only thing
you want in the header, or will the picture be joined with text? Certainly,
there are other questions, but I think you get the piont. If you simply want
the picture to appear in the heading by itself, then you can use something
like the following:

Dim oRng As Range
Set oRng = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
ActiveDocument.Fields.Add _
Range:=oRng, _
Type:=wdFieldIncludePicture, _
Text:="C:\\Test\\Test.gif \d", _
PreserveFormatting:=True

HTH,
Dave
 
D

Dave Lett

Hi Molly,

Sorry, I forgot that you wanted to show the dialog box first:

Dim oRng As Range
Set oRng = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
With Dialogs(wdDialogInsertPicture)
.Display
sName = Replace(.Name, "\", "\\")
End With
ActiveDocument.Fields.Add _
Range:=oRng, _
Type:=wdFieldIncludePicture, _
Text:=sName & " \d", _
PreserveFormatting:=True


HTH,
Dave
 

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