How do I combine 2 similar macros into one?

M

marcia

I have 2 macros that I use when working on documents to standardize
formatting of a particular phrase. Is there a way to combine them into one
macro?

Here are the 2:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Q Clearance"
.Replacement.Text = """Q"" Clearance"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

AND

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "'Q' Clearance"
.Replacement.Text = """Q"" Clearance"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub


Thanks for any help you can give me.
marcia
 
D

DaveLett

Hi Marcia,

You can use something like the following:

With Selection.Find
.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Text = "Q Clearance"
With .Replacement
.Text = """Q"" Clearance"
.ClearFormatting
End With
.Execute Replace:=wdReplaceAll

.Text = "'Q' Clearance"
.Execute Replace:=wdReplaceAll
End With
 
M

marcia

Dave, Thanks for the help.
Is there a way for the macro to put in quotation marks and not inch marks?
 
D

DaveLett

Hi Marcia,
I assume that you mean straight quotes. You can use something like the
following:

Dim bReplace As Boolean
'''store the current user setting
bReplace = Options.AutoFormatAsYouTypeReplaceQuotes
'''change the user setting
Options.AutoFormatAsYouTypeReplaceQuotes = True

With Selection.Find
..ClearFormatting
..Forward = True
..Wrap = wdFindContinue
..Format = False
..MatchCase = True
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
..Text = "Q Clearance"
With .Replacement
..Text = """Q"" Clearance"
..ClearFormatting
End With
..Execute Replace:=wdReplaceAll

..Text = "'Q' Clearance"
..Execute Replace:=wdReplaceAll
End With

'''restore the user's original setting
Options.AutoFormatAsYouTypeReplaceQuotes = False

HTH,
Dave
 

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