
Populate ImageBox Control on a VB Form
Hi Simon,
---I want to use VB code to pick up a "variable" picture in the Word
document and populate the picture in the imagebox control----
You can do this if you insert the pictures in the Word document as
{INCLUDEPICTURE} fields. If you turn on View Field Codes, then you will see
something like
{INCLUDEPICTURE "D:\\Graphics\\Gif\\AbortWarning.gif" \* MERGEFORMAT \d}
or
{INCLUDEPICTURE "D:\\Graphics\\Gif\\AbortWarning.gif" \* MERGEFORMAT }
In Word, you'd either bookmark this field or know its index position (as the
following example shows) so that you can reference it.
sImage = Replace(ActiveDocument.Fields(1).Code, " INCLUDEPICTURE", "")
sImage = Replace(sImage, " \* MERGEFORMAT \d ", "")
'Populate the imagebox control as soon as the form is
' executed
imgCoLogo.Picture = LoadPicture(sImage)
'Extracting a picture from an imagebox control in a
' UserForm
SavePicture imgCoLogo.Picture, sImage
HTH
Quote:
> I want to know if there is a way to extract a picture from
> a Word document and populate the imagebox control on a VB
> form without having to hard code the path of the graphic
> file. Then, I want to use VB code to take, or change, the
> picture loaded in the imagebox control and re-insert it
> into the Word document.
> The following is the VB code I have been working with. It
> only works if I hard code the path of the graphic file:
> 'Populate the imagebox control as soon as the form is
> executed
> imgCoLogo.Picture = LoadPicture("C:\Logos\logo.jpg")
> 'Extracting a picture from an imagebox control in a
> UserForm
> SavePicture imgCoLogo.Picture, "C:\Logos\logo.jpg"
> Simply put, I want to use VB code to pick up a "variable"
> picture in the Word document and populate the picture in
> the imagebox control. Then, I could change the picture in
> the imagebox control, and insert it back into the
> document. I guess I'm looking for some VB code that could
> deal with variables rather than having to explicitly state
> the path of the graphic file in parentheses as shown above
> in my code.
> Thanks for your help on this.
> Simon