H
HowdeeDoodee
Many times I record a macro to do repeated actions. As an example, I record
the macro to do one set of actions and store the macro in Alt-5. To run the
macro down the page I keep hitting Alt-5. However, when I reach the end of
the document, the macro goes back to the top of the document and starts over
again. This is bad because of the text in the document. How do I stop a macro
from executing if the macro has reached the end of the document. Here is an
example of a multiple step macro I want to stop when the bottom of the page
is reached.
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<p><a name="""
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.HomeKey Unit:=wdStory
ActiveWindow.ActivePane.SmallScroll Down:=4
Selection.Find.ClearFormatting
With Selection.Find
.Text = """>[GoTo]</a><br>"
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.TypeText Text:="}}}"
Selection.PasteAndFormat (wdPasteDefault)
Selection.Find.ClearFormatting
With Selection.Find
.Text = "</a><a href="
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.SmallScroll Down:=-1
Selection.Find.ClearFormatting
With Selection.Find
.Text = """>"
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.SmallScroll Down:=-2
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<p><a name="""
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<a href=""#"
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
the macro to do one set of actions and store the macro in Alt-5. To run the
macro down the page I keep hitting Alt-5. However, when I reach the end of
the document, the macro goes back to the top of the document and starts over
again. This is bad because of the text in the document. How do I stop a macro
from executing if the macro has reached the end of the document. Here is an
example of a multiple step macro I want to stop when the bottom of the page
is reached.
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<p><a name="""
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.HomeKey Unit:=wdStory
ActiveWindow.ActivePane.SmallScroll Down:=4
Selection.Find.ClearFormatting
With Selection.Find
.Text = """>[GoTo]</a><br>"
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.TypeText Text:="}}}"
Selection.PasteAndFormat (wdPasteDefault)
Selection.Find.ClearFormatting
With Selection.Find
.Text = "</a><a href="
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.SmallScroll Down:=-1
Selection.Find.ClearFormatting
With Selection.Find
.Text = """>"
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.SmallScroll Down:=-2
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<p><a name="""
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<a href=""#"
.Replacement.Text = "[GoTo]</a><br>^p"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub