P
Pete
Hi, I posted a question asking how to search for a word then select/range
the page the word is within. Doug Robbins kindly replied saying I could use
the built-in \Page bookmark. I've tried this and it fails. However - it
does work with other built-in bookmarks like \Para. So maybe this is a
bug - or my code is screwy? It's as if it ignores the page breaks in the
doc entirely. Any ideas would be great... thanks!
Dim pageText As String
Dim oPageRange As Range
Dim oPageBookmark As Bookmark
Dim oSel As Selection
Set oSel = Selection
oSel.Find.ClearFormatting
oSel.Find.ClearAllFuzzyOptions
oSel.Find.MatchCase = False
oSel.Find.Forward = True
oSel.Find.Wrap = wdFindContinue
oSel.Find.Text = "SomeTextToFind"
oSel.Find.Execute
If oSel.Find.Found = True Then
Set oPageBookmark = oSel.Bookmarks.Item("\Page")
Set oPageRange = oPageBookmark.Range
pageText = oPageRange.Text
MsgBox ("Found page: " & pageText)
End If
the page the word is within. Doug Robbins kindly replied saying I could use
the built-in \Page bookmark. I've tried this and it fails. However - it
does work with other built-in bookmarks like \Para. So maybe this is a
bug - or my code is screwy? It's as if it ignores the page breaks in the
doc entirely. Any ideas would be great... thanks!
Dim pageText As String
Dim oPageRange As Range
Dim oPageBookmark As Bookmark
Dim oSel As Selection
Set oSel = Selection
oSel.Find.ClearFormatting
oSel.Find.ClearAllFuzzyOptions
oSel.Find.MatchCase = False
oSel.Find.Forward = True
oSel.Find.Wrap = wdFindContinue
oSel.Find.Text = "SomeTextToFind"
oSel.Find.Execute
If oSel.Find.Found = True Then
Set oPageBookmark = oSel.Bookmarks.Item("\Page")
Set oPageRange = oPageBookmark.Range
pageText = oPageRange.Text
MsgBox ("Found page: " & pageText)
End If