Thread: [Solved] End or alter a loop?
View Single Post
 
Old 10-11-2013, 08:18 AM
DJSOUND DJSOUND is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Oct 2013
Posts: 1
DJSOUND is on a distinguished road
Default End or alter a loop?

Hi
I have this code below where I am looking for a certain character style, replacing the character two spaces preceding it with a comma (when text in the character style is "abc") and inserting a period immediately following the character style regardless of the text.
I have it working, but when I tried to do a loop it won't end. I've found that my method is probably not the correct one, but I can't figure out how to do it any other way. Is there a way to just tell the program to find an ending point that it will actually find?
Code:
Code:
Sub Macro9()
'
' Macro9 Macro
'
Do Until ActiveDocument.Bookmarks("\Sel") = ActiveDocument.Bookmarks("\EndOfDoc")
  Selection.Find.ClearFormatting
  Selection.Find.Style = ActiveDocument.Styles("one_car")
  Selection.Find.Replacement.ClearFormatting
  With Selection.Find
    .Text = "abc"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
   .MatchAllWordForms = False
  End With
  Selection.Find.Execute
  Selection.MoveLeft Unit:=wdCharacter, Count:=2
  Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
  Selection.TypeText Text:=","
  Selection.Find.ClearFormatting
  Selection.Find.Style = ActiveDocument.Styles("one_car")
  Selection.Find.Replacement.ClearFormatting
  With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
  End With
  Selection.Find.Execute
  Selection.MoveRight Unit:=wdCharacter, Count:=1
  Selection.TypeText Text:="."
Loop
End Sub

Thanks!

Last edited by macropod; 10-11-2013 at 07:49 PM. Reason: Added code tags & formatting
Reply With Quote