Hello,
I am quite fresh to Word VBA object model, therefore my code examples may be far away of proper solution. I will appreciate any help, hint which can help.
Here is my problem:
On my Word document I have many pages. On each page I have picture inserted. It is on bottom of a page, but it is not a footer yet.
I was able to remove old picture and add new one in the same place where the old was. Here is my routine:
[VBA]
Set oWrd = wrdApp.Documents.Open(sPath)
For i = oWrd.Shapes.Count To 1 Step -1
With oWrd.Shapes(i)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
dTop = .Top
dLeft = .Left
dHeight = .Height
dWidth = .Width
.Delete
End With
Set sh = oWrd.Shapes.AddPicture(sPathPicture, , True, dLeft - oWrd.PageSetup.LeftMargin, dTop - oWrd.PageSetup.TopMargin, dWidth, dHeight)
Next i
oWrd.Close True
[/VBA]
I've noticed that new pictures are added always on the first page. I believe that 'top' is being measured from the top of the 'current' page.
I've googled a little bit and found this piece of code:
[VBA]Set sh = oWrd.Shapes.AddPicture(sPathPicture, , True, dLeft - oWrd.PageSetup.LeftMargin, dTop - oWrd.PageSetup.TopMargin, dWidth, dHeight, oWrd.Range.GoTo(1, 2, PageNumber))[/VBA]
but I have no idea how to check the 'pagenumber' of respective shape.
To sum up:
I would like to delete all pictures from all pages (above routines do the job) and add new picture at the same coordinates.
Thanks in advance for your help.



Reply With Quote
