Insert Picture at a specific point in a document

V

Vinay

Hi,

I am trying to insert a image in a document. I am able to
do this with a following command:

.ActiveDocument.InlineShapes.AddPicture
(FileName:="Test1.jpg",
LinkToFile:=False, SaveWithDocument:=True)

but the problem is, it is inserting it in the begining of
the document.

Can someone help me to insert this image at the desired
location in the document (It may be middle or end of the
document).

Regards

Vinay
 
J

Jonathan West

Hi Vinay,

You need to include the Range parameter for the method, to specify where the
chape is added. For instanmce, if you want the picture added at the
selection point, use the following code

ActiveDocument.InlineShapes.AddPicture FileName:="Test1.jpg",
LinkToFile:=False, SaveWithDocument:=True, Range:=Selection.Range

You can specify any range you like. For instance, if you want the picture
added at the start of the second row of the first table in the document,
then you could do something like this

Dim myRange as Range
Set myRange = ActiveDocument.tables(1).Cell(2, 1).Range
myRange.Collapse Direction:=wdCollapseStart
ActiveDocument.InlineShapes.AddPicture FileName:="Test1.jpg",
LinkToFile:=False, SaveWithDocument:=True, Range:=myRange
 
V

Vinay

Hi Jonathan,

Thanks for your input. I would request you to give me a
bit more direction as I am not able to use the Range
parameter in the required way.

Before inserting this image, I am adding some text in a
document under a loop and I want at a specific line (say
5th), an image to be inserted followed by rest of text.
In the following code I have not defined any range and it
is inserting the text.

For iCount = 0 to 20
.ActiveDocument.range.insertafter(sField & vbcrLf)
'sField contains a text line
Next iCount

I have 2 queries:

1. How should I define Range parameter in the above case.
2. Is there any quick way of bringing the cursor at
specific point in a document.

Regards

Vinay
 

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