If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Creating a macro
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 |
#2
|
|||
|
|||
Creating a macro
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 Word MVP web site http://word.mvps.org 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 |
#3
|
|||
|
|||
Creating a macro
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 "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 |
#4
|
|||
|
|||
Creating a macro
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/...csIn15Mins.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. "dk" wrote in message ... 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 "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 |
#5
|
|||
|
|||
Creating a macro
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 "Charles Kenyon" wrote: 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/...csIn15Mins.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. "dk" wrote in message ... 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 "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 |
#6
|
|||
|
|||
Creating a macro
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 Word MVP web site http://word.mvps.org 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 "Charles Kenyon" wrote: 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/...csIn15Mins.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. "dk" wrote in message ... 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 "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 |
#7
|
|||
|
|||
Creating a macro
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. "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 "Charles Kenyon" wrote: 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/...csIn15Mins.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. "dk" wrote in message ... 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 "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 |
#8
|
|||
|
|||
Creating a macro
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 Word MVP web site http://word.mvps.org 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. "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 "Charles Kenyon" wrote: 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/...csIn15Mins.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. "dk" wrote in message ... 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 "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 |
#9
|
|||
|
|||
Creating a macro
this is the line with different color:
' Purpose: remove any of the characters in sBadChars from vPhrase also alot of times we have problems to reply to post why? "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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. "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 "Charles Kenyon" wrote: 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/...csIn15Mins.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. "dk" wrote in message ... 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 "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 |
#10
|
|||
|
|||
Creating a macro
That line does not appear in the code I posted so I haven't a clue what it
is you are doing. You seem to have some other macro code in there. Rename normal.dot to oldnormal.dot and start again with a blank sheet. As for posting - see http://www.gmayor.com/MSNews.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org dk wrote: this is the line with different color: ' Purpose: remove any of the characters in sBadChars from vPhrase also alot of times we have problems to reply to post why? "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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. "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 "Charles Kenyon" wrote: 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/...csIn15Mins.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. "dk" wrote in message ... 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 "Graham Mayor" wrote: 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 Word MVP web site http://word.mvps.org 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 |
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating Macro to generate automated email | Shery | General Discussion | 0 | October 4th, 2005 03:41 PM |
Creating a macro commad to shift selected rows to the right next c | Shifting of Multiple Row to the right | General Discussion | 1 | September 15th, 2005 03:31 AM |
Creating a macro that updates table fields | Gail | General Discussion | 1 | April 28th, 2005 11:56 PM |
word error | mac | General Discussions | 1 | May 6th, 2004 08:14 AM |
Creating a Relative Macro | Mar | Worksheet Functions | 3 | October 13th, 2003 01:50 AM |