Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I make my loop stop at the bottom of the file?

Status
Not open for further replies.

MaryAnn1985

Technical User
Oct 6, 2008
6
FI
I am writing a Microsoft Word macro and I want the macro to search the whole file for specific word endings and to write something in front of the words that have these specific endings. I used a loop, because the macro has to search the whole file for these endings, but it has to search the file only once (not over and over again), so I want the macro to stop at the bottom of the file. How can I do this? Thanks in advance!

This is an early version of the macro (including only one ending, namely -aisia ) :

Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = "aisia "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
If Not Selection.Find.Found Then Exit Do
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.TypeText Text:="<partitive>"
Loop Until Not Selection.Find.Found
End Sub
 
You really need to move this question to forum707.

--

"If to err is human, then I must be some kind of human!" -Me
 
Hi MaryAnn1985,

Jus check out with this coding...maybe this will help you out..insert these two modules in ur macro...
-------------

Private Sub Resetsearch()
With Selection.Find
.Parent.Collapse
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End Sub

-----------
Sub Wordrep1()
Resetsearch
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = "aisia"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
End Sub

-------------
And yes... do u wan to insert this "<partitive>"...let me know if this helps u out wid ur problem...

Thx..

JackHack
 
As a cross reference, here is the thread in the correct forum:
thread707-1504952


--

"If to err is human, then I must be some kind of human!" -Me
 
Thanks!! My macro works fine now!

thread707-1504952: How can I make my loop stop at the bottom of the file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top