tlangford
05-05-2008, 07:53 AM
Hi.
I used some code remove multiple spaces, which works really well. However, when I run the same code with track changes enabled, the results are completely wrong.
I can understand why this is happening, as the changes it makes in each iteration of the Selection.Find call are "pending", as they haven't been accepted yet.
:help Does anyone know how to have the code sucessfully remove multiple spaces, while tracking the changes? Btw, I'm tracking changes as the people I'm writing this for want to see what changes my macro is making to their documents.
Code follows...
Public Sub ReplaceMultipleSpaces()
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
'Here is where it is actually looking for spaces between words
.Text = " [ ]@([! ])"
'This line tells it to replace the excessive spaces with one space
.Replacement.Text = " \1"
.MatchWildcards = True
.Wrap = wdFindStop
.Format = False
.Forward = True
'execute the replace
.Execute Replace:=wdReplaceAll
End With
End Sub
I used some code remove multiple spaces, which works really well. However, when I run the same code with track changes enabled, the results are completely wrong.
I can understand why this is happening, as the changes it makes in each iteration of the Selection.Find call are "pending", as they haven't been accepted yet.
:help Does anyone know how to have the code sucessfully remove multiple spaces, while tracking the changes? Btw, I'm tracking changes as the people I'm writing this for want to see what changes my macro is making to their documents.
Code follows...
Public Sub ReplaceMultipleSpaces()
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
'Here is where it is actually looking for spaces between words
.Text = " [ ]@([! ])"
'This line tells it to replace the excessive spaces with one space
.Replacement.Text = " \1"
.MatchWildcards = True
.Wrap = wdFindStop
.Format = False
.Forward = True
'execute the replace
.Execute Replace:=wdReplaceAll
End With
End Sub