Consulting

Results 1 to 3 of 3

Thread: Replace all images into new ones

  1. #1

    Replace all images into new ones

    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.

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •