Hi all.
I currently have a template with a VBA form that allows my users to enter
data and have my report auto-build.
Unfortunately, I will need to be able to add an image to the document (along
with a caption) using the form mentioned above. I have managed to get the
image to be inserted into the document, but there are some issues.
First, the image is inserted at the beginning of the page. Not at the
bookmark. Of course, this is because I haven't associated the image with a
bookmark yet...no clue how to. Go figure.
Second, there is no user confirmation of the filename for the image selected
on the form.
I have a fairly simple solution, but I'm not sure how to put it into the code.
1. User clicks button next to text box.
2. Dialog opens allowing user to select a file from the pc.
3. Document name fills into the text box on the form which is next to said
button.
4. When user clicks 'submit' on the form, the code ties that filename to the
actual file and inserts it into the document AT MY BOOKMARK!!! =)
This process will need to be repeated multiple times, but there is no set
amount of times. As a result, I am putting about 5 bookmarks in for the
images (all on top of each other) and will need to put the line breaks into
the form to force the lines to move down if an image is inputted... (I think
I might be able to handle that part...MIGHT) If no image, the bookmarks just
sit next to the first picture harmlessly. There will always be at least one
image, but how many there will acutally be in the end will vary...
The basic text-inserts of the form are working beautifully, so I don't seem
to need any help there right now. What I need is a simple code sample that
will get me through steps 1 through 4 above. I can manipulate it to
accomodate my filenames and requirements, but I don't know where to begin!!!

Thanks in advance to anyone able or willing to help!
Kim

Re: Images, forms, and VBA in MS Word by Birgit

Birgit
Thu Sep 18 23:58:28 PDT 2008

Hi Kimberly,

You could put an IncludePicture field (that contains the path you are
getting from the dialog) at the bookmark.

The following code wil pick up the path and name of the selected file and
print it to the immediate window.

Sub GetMyPicFullName()
With Application.Dialogs(wdDialogInsertPicture)
antwoord = .Display
If antwoord = -1 Then Debug.Print .Name
End With
End Sub

HTH,
Birgit

"Kimberly3626" <Kimberly3626@discussions.microsoft.com> schreef in bericht
news:229C1EB2-59B8-46A5-92A2-005E81B9AB1F@microsoft.com...
> Hi all.
> I currently have a template with a VBA form that allows my users to enter
> data and have my report auto-build.
> Unfortunately, I will need to be able to add an image to the document
> (along
> with a caption) using the form mentioned above. I have managed to get the
> image to be inserted into the document, but there are some issues.
> First, the image is inserted at the beginning of the page. Not at the
> bookmark. Of course, this is because I haven't associated the image with
> a
> bookmark yet...no clue how to. Go figure.
> Second, there is no user confirmation of the filename for the image
> selected
> on the form.
> I have a fairly simple solution, but I'm not sure how to put it into the
> code.
> 1. User clicks button next to text box.
> 2. Dialog opens allowing user to select a file from the pc.
> 3. Document name fills into the text box on the form which is next to said
> button.
> 4. When user clicks 'submit' on the form, the code ties that filename to
> the
> actual file and inserts it into the document AT MY BOOKMARK!!! =)
> This process will need to be repeated multiple times, but there is no set
> amount of times. As a result, I am putting about 5 bookmarks in for the
> images (all on top of each other) and will need to put the line breaks
> into
> the form to force the lines to move down if an image is inputted... (I
> think
> I might be able to handle that part...MIGHT) If no image, the bookmarks
> just
> sit next to the first picture harmlessly. There will always be at least
> one
> image, but how many there will acutally be in the end will vary...
> The basic text-inserts of the form are working beautifully, so I don't
> seem
> to need any help there right now. What I need is a simple code sample
> that
> will get me through steps 1 through 4 above. I can manipulate it to
> accomodate my filenames and requirements, but I don't know where to
> begin!!!
>
> Thanks in advance to anyone able or willing to help!
> Kim