INserting pictures Through VBA Form

P

ph_cooper

hello,
i am new to VBA and could really use some advice.
i am trying to use a userform to browse for a picture(s). i would like to be
able to loacte the file in my form and fill the rest out then by clicking ok,
have it insert it into my document. which is the best way to go at this??

any help will be greatly appreciated.
Andy Ware
 
J

Jay Freedman

hello,
i am new to VBA and could really use some advice.
i am trying to use a userform to browse for a picture(s). i would like to be
able to loacte the file in my form and fill the rest out then by clicking ok,
have it insert it into my document. which is the best way to go at this??

any help will be greatly appreciated.
Andy Ware

You can use the built-in Insert > Picture > From File dialog. Here's a
code snippet:

With Dialogs(wdDialogInsertPicture)
If .Display <> -1 Then GoTo Canceled

' get chosen file's full path and file name
FName = WordBasic.FileNameInfo$(.Name, 1)
End With

Later, having set the Range object PicRg to point to the place where
the picture should be inserted, use the saved file name like this:

Dim Photo As InlineShape
Set Photo = .InlineShapes.AddPicture(FileName:=FName, _
LinkToFile:=False, SaveWithDocument:=True, _
Range:=PicRg)

Then modify the properties of the object Photo to set the desired size
and other formatting.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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