Insert picture in a speicific location within a document

M

msxkim

I'm trying to insert a picture in a speicific location within a word
document from a vb.net application.
It was not that difficult simply to insert a picture on the current
cusor
position but I don't know how to insert a bmp (or jpg) image on the
botton of last page only. I couldn't insert a picture in a speicific
location which I want.
If you have any idea, Please help this novice. I am using Word 2003
Thank you.
 
K

Karl E. Peterson

If you have any idea, Please help this novice.

The thing that saved me, the only time I ever wanted to do what you're doing, was
turning on the Macro recorder and watching what it produced when I manually did what
I wanted. HTH!
 
B

Bear

Karl:

Word maintains several predefined bookmarks. One may help you get to the end
of the document. Here's some text from the VBA help files.

~~~~~
Word sets and automatically updates a number of reserved bookmarks. You can
use these predefined bookmarks just as you use the ones that you place in
documents, except that you don't have to set them and they are not listed on
the Go To tab in the Find and Replace dialog box (Edit menu).

You can use predefined bookmarks with the Bookmarks property. The following
example sets the bookmark named "currpara" to the location marked by the
predefined bookmark named "\Para."

ActiveDocument.Bookmarks("\Para").Copy "currpara"
~~~~~

The bookmarks are all listed in this topic, but the one you want seems to be:

\EndOfDoc


Bear
 
H

Helmut Weber

Hi,

like this:

Sub Macro3()
Dim oShp As Shape
Set oShp = ActiveDocument.Shapes.AddPicture( _
FileName:="C:\Pic\bluehills.jpg", _
Anchor:=ActiveDocument.Paragraphs.Last.Range)
oShp.Top = -300
' ... plus some more

End Sub

' ---------------------------------------

Sub Macro3A()
Dim oShp As Shape
Dim rTmp As Range
ActiveDocument.Bookmarks("\endofdoc").Select
ActiveDocument.Bookmarks("\page").Select
Set rTmp =
Selection.Bookmarks("\page").Range.Paragraphs.First.Next.Range
Set oShp = ActiveDocument.Shapes.AddPicture( _
FileName:="C:\Pic\bluehills.jpg", _
Anchor:=rTmp)
oShp.Top = 100
' ... plus some more
End Sub

There are lots of caveats,
e.g. whether the first paragraph on the last page
(Macro3A) starts on that page.
Therefore I used
Set rTmp =
Selection.Bookmarks("\page").Range.Paragraphs.First.Next.Range
But what if there is only one paragraph on that page?

Or, for Macro3, what if the only paragraph on the
last page starts on the page before?

However, trying one third variation
with what the help says for omitting anchor,
Word crashes.

HTH, nevertheless

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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