|
-
May 4th, 2011, 04:05 AM
#1
Thread Starter
New Member
Using the find method to find a style and recording the page it was found on
Hi,
I am trying to write a macro that will search through the active document, find all instances of a style, then print out the text and the page number the text is on. I am using the following code snippet to test this:
vb Code:
With ActiveDocument.Content.Find
.ClearFormatting
.Style = "Table Title"
'The Do...Loop statement repeats a series of
' actions each time this style is found.
Do While .Execute(Forward:=True, Format:=True) = True
strCode = .Parent & vbTab & Selection.Information(wdActiveEndAdjustedPageNumber)
MsgBox strCode
.Parent.Move Unit:=wdParagraph, Count:=1
Loop
End With
Which seems to work OK, however, since the Content returns a range object, it does not cause the selection to change and hence the page number reported is always the LAST page of the document, rather than the page on which the text was found (this text is from the help on the find property: Note When this property is used with a Selection object, the selection is changed if the find operation is successful. If this property is used with a Range object, the selection isn't changed unless the Select method is applied.
So what I want to know is how to "select" this line such that the page number reports correctly.
thanks in advance!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|