View Single Post
 
Old 10-12-2014, 07:36 AM
Marko Marko is offline Windows 7 64bit Office 2003
Novice
 
Join Date: Oct 2014
Posts: 2
Marko is on a distinguished road
Default Help required with Selection.Find to search a text file.

I am trying to write a macro to search through a large text file to find page numbers. These numbers are on their own lines with no other text. I want to check that all the line numbers are there and in the correct order. I want to start at the top of the first page and then search for the first number. Then search down from the first number to find the next, and so on. I have started with the following macro.

'Goto the top of page 1
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"

For n = 1 To 100
t = "^p" & n & "^p"

With Selection.Find
.ClearFormatting
.Text = t
.Forward = True
.Wrap = wdFindStop
End With

If Selection.Find.Execute = False Then Stop

Next n

This will only find the first line number. If I change the .Wrap line to wdFindContinue it will go back and search the whole document, not just from where the previous search stopped. So this will not show if the page numbers are out of sequence.

If anyone can point me in the right direction it would be greatly appreciated. I am using Word 2003 and Windows 7.
Reply With Quote