Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-12-2014, 07:36 AM
Marko Marko is offline Help required with Selection.Find to search a text file. Windows 7 64bit Help required with Selection.Find to search a text file. Office 2003
Novice
Help required with Selection.Find to search a text file.
 
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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to Find and Format Text string defined using Inputbox within selection sistemalan Word VBA 7 10-03-2014 07:28 AM
Help required with Selection.Find to search a text file. Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
Help required with Selection.Find to search a text file. Selection of all Text for a specific page in word is spanning selection across pages ramsgarla Word VBA 9 12-05-2012 03:23 AM
Help! Find text in doc file & copy to another file northstarman Word 1 11-05-2010 08:15 AM
Automatic find replace after selection in dropdown vsempoux Word 0 10-28-2009 08:45 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft