I am formatting some text with a macro. The macro searches for a marker
value "][", inserts a manual line break, selects to the end of the paragraph,
italicizes the selection.
I want to repeat this macro through the entire document. I'm just not sure
how to go about forming the loop that does this.
Here is the macro code that performs the operation one time.:
Sub AddTTPCommentBreak()
'
' AddTTPCommentBreak Macro
' Macro recorded 9/19/2006
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "]["
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.TypeText Text:=Chr(11)
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Italic = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
You don't really need a loop for this; instead, you can use a Find/Replace
to handle this.
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Text = "(\]\[)(*)(^13)"
.MatchWildcards = True
With .Replacement
.ClearFormatting
.Text = "\1^l\2\3"
.Font.Italic = True
End With
.Execute Replace:=wdReplaceAll
End With
End With
^l (the el letter) is the manual line break. I've put it after the "][".
HTH,
Dave
>I am formatting some text with a macro. The macro searches for a marker
> value "][", inserts a manual line break, selects to the end of the
[quoted text clipped - 32 lines]
> Selection.MoveRight Unit:=wdCharacter, Count:=1
> End Sub
Richard Winks - 19 Sep 2006 19:11 GMT
Close enough. Thanks Dave
Grace - 21 Sep 2006 05:39 GMT
How would i write a loop to replace a page break with a next page section
break? The next page section break is not one of the items that you can
replace with, a section break is only listed as one of the things you can
find.
> You don't really need a loop for this; instead, you can use a Find/Replace
> to handle this.
[quoted text clipped - 55 lines]
> > Selection.MoveRight Unit:=wdCharacter, Count:=1
> > End Sub
Richard Winks - 21 Sep 2006 12:31 GMT
Grace,
Use ^m (manual page break) instead of ^l (el) in substitution text.
Dick
Doug Robbins - Word MVP - 21 Sep 2006 21:37 GMT
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^m", MatchWildcards:=False,
Wrap:=wdFindStop, Forward:=True) = True
Selection.Range.Delete
Selection.InsertBreak Type:=wdSectionBreakNextPage
Loop
End With

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> How would i write a loop to replace a page break with a next page section
> break? The next page section break is not one of the items that you can
[quoted text clipped - 61 lines]
>> > Selection.MoveRight Unit:=wdCharacter, Count:=1
>> > End Sub
Grace - 17 Oct 2006 15:06 GMT
I created a macro and copied what you had below. I get a
Compile Error:
Expected: named parameter
message.
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
[quoted text clipped - 71 lines]
> >> > Selection.MoveRight Unit:=wdCharacter, Count:=1
> >> > End Sub
Doug Robbins - Word MVP - 17 Oct 2006 19:50 GMT
The mail program has inserted a line break that splits one line of code into
two
The following needs to be all on one line:
Do While .Execute(FindText:="^m", MatchWildcards:=False,
Wrap:=wdFindStop, Forward:=True) = True
or must have a line break character inserted in the appropriate place
Do While .Execute(FindText:="^m", MatchWildcards:=False, _
Wrap:=wdFindStop, Forward:=True) = True

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>I created a macro and copied what you had below. I get a
>
[quoted text clipped - 84 lines]
>> >> > Selection.MoveRight Unit:=wdCharacter, Count:=1
>> >> > End Sub