Condition of the end of the file in MACRO

T

Tomá¹ Vognar

EN:
I've recorded a macro in Word. Now I want the macro to be repeated until the
end of the document. If I enclose the code with Do and Loop, it's cycling,
naturally. What condition should I write behind the keyword While (or
Until)?


CZ:
Zaznamenal jsem si ve Wordu makro, které vybarví øádek, kdy¾ na nìm najde
urèité znaky. Chci, aby se makro opakovalo a¾ do konce dokumentu, a pak
skonèilo. Ohranièil jsem ho zatím Do a Loop, tím se samozøejmì zacyklilo. Co
napsat za Until... (While...)?
 
T

Tomá¹ Vognar

We have special log files. I need to change color of the line containing
"STRING", finishing the char "CR", and repeat it until the end of the file.
I solved it this way.

1) But the loop runs at 101%. It colors one more line, next to the last
occurence of the "STRING".
2) Some lines are too long to be visible as whole and are represented as 2
visible lines. Then, the char "CR" is on the second visible line. But my
code highlights the line only until the visible end. I just don't know, how
to find "STRING", then find next "CR", and then to highlight the space
between it.


Selection.Find.ClearFormatting
With Selection.Find
.Text = " 1S:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Color = wdColorGreen
Selection.MoveRight Unit:=wdCharacter, Count:=1
Loop Until Selection.Find.Found = False
End Sub

T.V.

Howard Kaikow said:
It depends on what you are doing.
You will need to supply more details.
--
http://www.standards.com/; See Howard Kaikow's web site.
Tomá¹ Vognar said:
EN:
I've recorded a macro in Word. Now I want the macro to be repeated until the
end of the document. If I enclose the code with Do and Loop, it's cycling,
naturally. What condition should I write behind the keyword While (or
Until)?


CZ:
Zaznamenal jsem si ve Wordu makro, které vybarví øádek, kdy¾ na nìm najde
urèité znaky. Chci, aby se makro opakovalo a¾ do konce dokumentu, a pak
skonèilo. Ohranièil jsem ho zatím Do a Loop, tím se samozøejmì
zacyklilo.
 
C

Chad DeMeyer

Tomas,

Suggest you rework your code like this:

With Selection.Find
.ClearFormatting
.Text = "1S:"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
Do While .Found
Selection.Paragraphs(1).Range.Font.Color = wdColorGreen
Selection.Collapse wdCollapseEnd
.Execute
Loop
End With

Regards,
Chad


Tomá¹ Vognar said:
We have special log files. I need to change color of the line containing
"STRING", finishing the char "CR", and repeat it until the end of the file.
I solved it this way.

1) But the loop runs at 101%. It colors one more line, next to the last
occurence of the "STRING".
2) Some lines are too long to be visible as whole and are represented as 2
visible lines. Then, the char "CR" is on the second visible line. But my
code highlights the line only until the visible end. I just don't know, how
to find "STRING", then find next "CR", and then to highlight the space
between it.


Selection.Find.ClearFormatting
With Selection.Find
.Text = " 1S:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Color = wdColorGreen
Selection.MoveRight Unit:=wdCharacter, Count:=1
Loop Until Selection.Find.Found = False
End Sub

T.V.
 
T

Tomá¹ Vognar

Thank you, Chad, your code runs correctly. VBA is not my business ....
T.Vognar
 
Top