HowdeeDoodee
Technical User
I want to make the following MS Word macros loop and stop at either the top of the file or the bottom of the file. Thank you in advance for your replies.
-----------------------------------
Macro 1
'
'This macro does not stop when the bottom of file is reached. I want this macro to stop executing when the bottom of the file is reached.
Selection.Find.ClearFormatting
With Selection.Find
.Text = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab _
& vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab
.Replacement.Text = ""
.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
With Selection.Font
.Name = ""
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
---------------------------
Macro 2
'
'
'This macro does not stop at the top of the file when TOF is reached. I want this macro to stop executing when the top of the file is reached. This macro runs from the botttom of the document.
Selection.Find.ClearFormatting
Do While Not TOF
Selection.Find.Font.Bold = True
With Selection.Find
.Text = "*"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=vbTab & vbTab
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=vbTab & vbTab
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Loop
-----------------------------------
Macro 1
'
'This macro does not stop when the bottom of file is reached. I want this macro to stop executing when the bottom of the file is reached.
Selection.Find.ClearFormatting
With Selection.Find
.Text = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab _
& vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab
.Replacement.Text = ""
.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
With Selection.Font
.Name = ""
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
---------------------------
Macro 2
'
'
'This macro does not stop at the top of the file when TOF is reached. I want this macro to stop executing when the top of the file is reached. This macro runs from the botttom of the document.
Selection.Find.ClearFormatting
Do While Not TOF
Selection.Find.Font.Bold = True
With Selection.Find
.Text = "*"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=vbTab & vbTab
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=vbTab & vbTab
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Loop