Cleaning Up After Macro Runs

M

mcp6453

The following macro works well to turn two or more sequential spaces
into a single space:

With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = " {2,}" 'Search for two or more spaces
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True 'Set this to true.
.Execute Replace:=wdReplaceAll
End With

However, after the macro runs, "MatchWildcards" remains set to True. How
can I set it to False? What other clean up would be a good practice to
follow after running this macro?
 
T

Tony Jollans

The best practice would be to use a Range rather than the Selection:

Set TempRange = Selection.Range
With TempRange.Find
' rest of your code
End With
Set TempRange = Nothing

This way, no settings of the Selection.Find object get changed at all.
 
M

mcp6453

Tony said:
The best practice would be to use a Range rather than the Selection:

Set TempRange = Selection.Range
With TempRange.Find
' rest of your code
End With
Set TempRange = Nothing

This way, no settings of the Selection.Find object get changed at all.


Beautiful. Thanks. I sure wish I understood this stuff better.

Can you recommend a book or online course?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top