I have a vbscript that opens a Word document and uses regexp to search for 8 digit numbers. That part is working. I now would like to display the page number of where the 8 digit number was found. I am trying to use 'wdActiveEndPageNumber', but it is always printing the last page of the document as the page number. Below is the script. Can anyone tell me what I am going wrong?
TIA!
John
----------------------------------
Const wdStatisticPages = 2
Const wdActiveEndPageNumber = 3
Dim sFSpec : sFSpec = "Word.docx"
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim wrdApp : Set wrdApp = CreateObject("Word.Application")
Dim wrdDoc : Set wrdDoc = wrdApp.Documents.Open( oFS.GetAbsolutePathName( sFSpec ) )
WScript.Echo "Pages:", wrdDoc.ComputeStatistics(wdStatisticPages)
Set RegExp = CreateObject("VBScript.RegExp")
count = 0
With RegExp
.Global = True
.Pattern = "\d{8}"
For Each Match In RegExp.Execute(wrdApp.ActiveDocument.Range.Text)
Set myRange = wrdApp.ActiveDocument.Range
Wscript.Echo Match & ", Page - " & myRange.Information(wdActiveEndPageNumber)
count = count + 1
wrdApp.Selection.GoTo 0
Next
End With
Wscript.Echo vbCrLf & "Found - " & count & " match(es)"
wrdApp.Quit wdDoNotSaveChanges