Open the macro editor (ALT+F11) and see which line is flagged in
error. If you have not used macros before there should only be this
code in the editor and the errant line will be highlighted.
From the Run menu - click reset and try again. Do you still get the
error? Which line?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
dk wrote:
we went to macro created new macro we copied the following
Sub Commas()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Mrs([!,])"
.Replacement.Text = "Mrs,\1"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub
with hit run, again we got the same error
"compile error line number" etc.
:
Replace all that lot with:
Sub Commas()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Mrs([!,])"
.Replacement.Text = "Mrs,\1"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub
This will replace all instances of Mrs with Mrs, unless there is
already a comma present.
If you want to do the same for eg Mr and Dr then you can either
daisychain the macros or use an array to present the items eg
Sub ReplaceMyList()
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long
vFindText = Array("Mrs([!,])", "Mr([!s,])", "Dr([!,])")
vReplText = Array("Mrs,\1", "Mr,\1", "Dr,\1")
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = True
For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText(i)
.Execute replace:=wdReplaceAll
Next i
End With
End Sub
See
http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
dk wrote:
this is the macro
With Selection.Find
.ClearFormatting
.Text = "Mrs"
With .Replacement
.ClearFormatting
.Text = "Mrs,"
End With
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute replace:=wdReplaceAll
End With
Sub AddinInit()
'
' AddinInit Macro
' Macro created 10/31/2005 by David Katz
'
End Sub
Sub commas()
'
' commas Macro
' Macro recorded 10/31/2005 by David Katz
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Mrs"
.Replacement.Text = "Mrs,"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub
:
Alt-F11 opens the vba editor interface.
You may want to look at:
http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm and
http://word.mvps.org/FAQs/MacrosVBA/VBABasicsIn15Mins.htm.
--
Charles Kenyon
Word New User FAQ & Web Directory:
http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version
of Microsoft's Legal Users' Guide)
http://addbalance.com/usersguide
See also the MVP FAQ:
http://word.mvps.org/FAQs/ which is
awesome! --------- --------- --------- --------- ---------
---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
were can we find the code ? we are new in the macro we are just
recording and
running the find replace function in regular mode
:
As you have not included the errant code in your message it is
impossible to
troubleshoot it, but there's clearly a syntax error. The macro
recorder does
not handle all aspects of the replace tool properly and some
replace functions will have to be coded manually - and yes you
can have several replace functions in a single macro. - paste
the code into your reply and let us know what it is supposed to
do!
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
dk wrote:
We Have never used a macro, but we have multiple documents
that we have to do same find & replace for ex; adding commas
before address etc. we tryied recording a macro & using the
find and replace fuction we ran it in regular mode then we
stopped the macro and tried running the macro in the same
file we received a error compile error ; expected line number
or label number at end of statement what should we do over
here
Also we would like to have several find & replace in one macro
is that possible