How do I repeat macro action through document

R

Richard Winks

It has been asked many times and I can see how to create a loop for the macro
but I do not know how to get the action to start and the beginning and
continue to the end of the active document.

Any help is appreciated.
 
D

Dave Lett

What are you trying to loop through or what are to trying to do unitl the
end of the document?
 
R

Richard Winks

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
 
D

Dave Lett

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
 
G

Grace

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.

Dave Lett said:
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

Richard Winks said:
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
 
R

Richard Winks

Grace,

Use ^m (manual page break) instead of ^l (el) in substitution text.

Dick
 
D

Doug Robbins - Word MVP

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


--
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

Grace said:
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.

Dave Lett said:
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

Richard Winks said:
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
 
G

Grace

I created a macro and copied what you had below. I get a

Compile Error:
Expected: named parameter

message.

Doug Robbins - Word MVP said:
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


--
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

Grace said:
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.

Dave Lett said:
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
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
 
D

Doug Robbins - Word MVP

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

--
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

Grace said:
I created a macro and copied what you had below. I get a

Compile Error:
Expected: named parameter

message.

Doug Robbins - Word MVP said:
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


--
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

Grace said:
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.

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

message
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top