Replace all images into new ones

Joined
Aug 3, 2012
Messages
1
Reaction score
0
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:

Code:
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

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:

Code:
Set sh = oWrd.Shapes.AddPicture(sPathPicture, , True, dLeft - oWrd.PageSetup.LeftMargin, dTop - oWrd.PageSetup.TopMargin, dWidth, dHeight, oWrd.Range.GoTo(1, 2, PageNumber))

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.
 

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