Insert Pictures in MS Word at a Specific Location

J

jamiedora

I wish to know if there is an example code or a remedy for insterting a
picture file (via VBA automation from MS Access).

I am wrting a document generation code and need to insert a picture
after certain headers and paragrhaphs. I can insert the picture, but
it always appears at the top of the document. Is there a way around
this, that is insert the floating shape after the last line of text?

Thanks,

Set shp = SubWordDocument.Shapes.AddPicture(PicturePath & "\" &
strPicture2)
With shp 'Change size and position
.LockAspectRatio = msoFalse
.Height = InchesToPoints(2)
.Width = InchesToPoints(3)
.Line.Style = msoLineSingle
.Line.Weight = 2
.Line.ForeColor = vbBlack
.Line.DashStyle = msoLineSolid
.Left = wdShapeCenter
.RelativeVerticalPosition = wdRelativeVerticalPositionLine
.Top = InchesToPoints(0)
End With
SubWordDocument.Sections.last.Range.Collapse
 
J

Jezebel

Every graphic in a document is anchored to a single paragraph. This
determines the page that graphic is on (always the same page as the anchor)
and also the position if relative. You can specify this paragraph as an
argument to the AddPicture() function. Eg, to anchor to the last paragraph
of the document --

Dim pPar as Word.Range

Set pPar =
SubWordDocument.Paragraphs(SubWordDocument.Paragraphs.Count).Range
Set shp = SubWordDocument.Shapes.AddPicture( _
FileName:=PicturePath & "\" & strPicture2, _
Anchor:=pPar)
 
J

jamiedora

Thanks for the help,

One more question. After the picture is instered, because I'm
automating and pasting text, the next series of text to be pasted
deletes the picture. How can I direct word to paste the text directly
below the inserted picture. Ideally, the sequence below is what I'm
hopping to achieve:

- Paste Text
- Insert Picture
- Paste Text
 
J

Jezebel

If pasting more text is deleting the picture, then you are pasting over the
paragraph that contains the graphic; in effect, deleting the anchor, as
explained previously. Instead of pasting your text, try using one of the
Insert or InsertAfter methods.
 
J

Jezebel

If pasting more text is deleting the picture, then you are pasting over the
paragraph that contains the graphic; in effect, deleting the anchor, as
explained previously. Instead of pasting your text, try using one of the
Insert or InsertAfter methods.
 

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

Similar Threads


Top