thegreg
04-02-2010, 09:28 AM
Hi, everyone. I'm new here. I'm fairly new to Word macros, too. I'm just having a problem with this macro and I don't know what I'm doing wrong.
The point of this macro is to highlight each line of the document, search to see if it has this string of text (|100=), if it does, just move down to the next line and search that one. If it doesn't, then I need it to either do a backspace or maybe prompt the user. Here's what I have
Do
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "|100="
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
If Selection.Find.Found = False Then
Selection.HomeKey Unit:=wdLine
Selection.TypeBackspace
Selection.MoveDown Unit:=wdLine, Count:=1
Else
Selection.MoveDown Unit:=wdLine, Count:=1
End If
Loop Until (Selection.End = ActiveDocument.Content.End - 1)
I also tried it with
If Selection.Find.Execute Then
(move down a line)
Else
(Do the 'homekey, backspace' thing)
Any ideas how I can make this work? Thanks so much for any help!
The point of this macro is to highlight each line of the document, search to see if it has this string of text (|100=), if it does, just move down to the next line and search that one. If it doesn't, then I need it to either do a backspace or maybe prompt the user. Here's what I have
Do
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "|100="
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
If Selection.Find.Found = False Then
Selection.HomeKey Unit:=wdLine
Selection.TypeBackspace
Selection.MoveDown Unit:=wdLine, Count:=1
Else
Selection.MoveDown Unit:=wdLine, Count:=1
End If
Loop Until (Selection.End = ActiveDocument.Content.End - 1)
I also tried it with
If Selection.Find.Execute Then
(move down a line)
Else
(Do the 'homekey, backspace' thing)
Any ideas how I can make this work? Thanks so much for any help!