K
kpm
I am relatively new to writing macros and have a feeling I am missing one
step, but I am trying to write a macro that searches up for an occurrence of
the word article followed by a space and any number and another space. I
then want it to delete the space, and insert a tab. The macro works fine,
but for some reason, it is not looping. If you have any suggestions, I would
greatly appreciate it. here is what I have so far:
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
Do
With Selection.Find
.Text = "article ^# "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Loop Until Condition = False
End Sub
step, but I am trying to write a macro that searches up for an occurrence of
the word article followed by a space and any number and another space. I
then want it to delete the space, and insert a tab. The macro works fine,
but for some reason, it is not looping. If you have any suggestions, I would
greatly appreciate it. here is what I have so far:
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
Do
With Selection.Find
.Text = "article ^# "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Loop Until Condition = False
End Sub