0

I would like to retrieve the number of the page a picture is on. I know how to retrieve the picture using

ActiveDocument.Range.ShapeRange.LinkFormat.SourceFullName 

but what variable holds the pagenumber of a picture?

braX
  • 11,506
  • 5
  • 20
  • 33
SoftwareTester
  • 1,048
  • 1
  • 10
  • 25
  • See https://learn.microsoft.com/en-us/office/vba/api/word.range.information and https://learn.microsoft.com/en-us/office/vba/api/word.wdinformation – Tim Williams Jul 31 '20 at 05:15

2 Answers2

0

https://word.tips.net/T000728_Determining_the_Current_Page_Number.html

CurPage = Selection.Information(wdActiveEndAdjustedPageNumber)
CurPage = Selection.Information(wdActiveEndPageNumber)

How about this?

Maybe you could change it to:

ActiveDocument.Range.ShapeRange.Information(wdActiveEndAdjustedPageNumber)
ActiveDocument.Range.ShapeRange.Information(wdActiveEndPageNumber)

Not tested as on a Linux machine right now!!

Lewis Morris
  • 1,916
  • 2
  • 28
  • 39
0

The following code will create a list of pictures including the page it is located on.

... Sub LoopPages() With ActiveDocument Dim numPages As Integer: numPages = .Content.ComputeStatistics(wdStatisticPages) Dim actPage As Integer Dim rng As Range

    Dim num As Integer

    Dim FileOut As String:    FileOut = "c:\Temp\Images\Pages.txt"
    Open FileOut For Output As #1

    For actPage = 1 To numPages

        ' Create a range of Page actPage
        Set rng = .GoTo(What:=wdGoToPage, Name:=actPage)
        Set rng = rng.GoTo(What:=wdGoToBookmark, Name:="\page")
        
        For Each Shp In rng.ShapeRange
            With Shp
                If (.Type = msoLinkedPicture) Then
                    num = num + 1
                    Print #1, Format(num, "000") & " --> Page= " & actPage & " --> " & .LinkFormat.SourceFullName
                End If
            End With
        Next Shp
        
        For Each Shp In rng.InlineShapes
            With Shp
                If (.Type = wdInlineShapeLinkedPicture) Then
                    num = num + 1
                    Print #1, Format(num, "000") & " --> Page= " & actPage & " --> " & .LinkFormat.SourceFullName
                End If
            End With
        Next Shp

    Next actPage
    MsgBox num
    
    Close #1
End With

End Sub ...

SoftwareTester
  • 1,048
  • 1
  • 10
  • 25