PDA

View Full Version : Trouble with addpicture



xeem22
10-16-2008, 09:59 AM
Hi,
This is my first post, been checking on here before an found loads of answers but for the first time I need some more specific help.

I'm having troubles with a word 2003 macro, basically I want it to insert an image (doing it by link rather than embedding it into the document) have that image appear at the top edge of the page and then go the the next page of the document and repeat this.

This is the code I have so far:

Sub InsertImage()

Dim StartupPath As String
Dim ImagePath As String

StartupPath = Options.DefaultFilePath(wdStartupPath) & "\" 'uses startup path to find qamecanix folder

ImagePath = StartupPath & "ImageSource\"

Page = 1
NPage = Application.ActiveDocument.BuiltInDocumentProperties(14)

Do While Page <= NPage

ActiveDocument.Shapes.AddPicture(FileName:=ImagePath & "QA.eps", _
LinkToFile:=True, SaveWithDocument:=False, _
Left:=CentimetersToPoints(17.1), Top:=0).Select

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext

Page = Page + 1

Loop


End Sub

I have it select the image so that I can name it (haven't implemented that into the code yet)

I'm having 2 problems. The first is that it is inserting the image relative to the margins rather than the page. Looking at the msdn resources, it says it should be the page.

The second is that although it selects the next page along, it inserts the image on the 1st page (on top of the previously inserted image).

Please can anyone help as I've been really struggling with this one.

Thanks!

mphill
10-16-2008, 03:32 PM
See if this helps. I used two bookmarks, firstPicture and secondPiture, in the document for the location. Then added the picture to the bookmark location and sent the picture behind the text. The firstPicture is in the upper left and the secondPicture is in the upper right.


Dim oRngA As Range
Dim oRngB As Range

Set oRngA = ActiveDocument.Bookmarks("firstPicture").Range
ActiveDocument.Shapes.AddPicture "C:\temp\picture1.tif", False, _ True, 5, 0, 60, 60, oRngA
ActiveDocument.Shapes(1).ZOrder msoSendBehindText

Set oRngB = ActiveDocument.Bookmarks("secondPicture").Range
ActiveDocument.Shapes.AddPicture "C:\temp\picture2.tif", False, _ True, 440, 0, 60, 60, oRngB
ActiveDocument.Shapes(2).ZOrder msoSendBehindText

xeem22
10-23-2008, 02:01 AM
Thanks for this, sadly what I need to do needs to work on different types of documents so I won't be able to use bookmarks.

Has anyone else got any ideas?

Thanks again!