I recorded and edited this macro to remove unwanted characters from a word 2003 document. It does what I wanted and allows me to add or change the characters as needed, but it seems the code is very redundent and probably could be shortened to accomplish the same results. Any help on this would be very much appreciated. Thanks in advance. Joe _________________________________________________________ Sub Macro1() ' ' Macro1 Macro ' Macro recorded 8/14/2005 by Joe Payne ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "?" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "/" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "+" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ">" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "@" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ")" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "(" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "~" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "%" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "#" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "$" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "=" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "*" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "|" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "-" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ";" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ":" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub
With UseWildcards set to TRUE you can do them all in one go -- With Selection.Find .Text = "[\?\/+>\@\)\(~%#$=\*|\-;:]" .Replacement.Text = "" .MatchWildcards = true .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With wrote in message news:k18rv1pfk78ubmgt4grc1oj5j5g40psbrc@4ax.com... >I recorded and edited this macro to remove unwanted characters from a > word 2003 document. It does what I wanted and allows me to add or > change the characters as needed, but it seems the code is very > redundent and probably could be shortened to accomplish the same > results. Any help on this would be very much appreciated. Thanks in > advance. Joe > > _________________________________________________________ > > Sub Macro1() > ' > ' Macro1 Macro > ' Macro recorded 8/14/2005 by Joe Payne > ' > Selection.Find.ClearFormatting > Selection.Find.Replacement.ClearFormatting > With Selection.Find > .Text = "?" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute Replace:=wdReplaceAll > Selection.Find.Execute > Selection.Find.ClearFormatting > Selection.Find.Replacement.ClearFormatting > With Selection.Find > .Text = "/" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "+" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = ">" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "@" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = ")" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "(" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "~" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "%" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "#" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "$" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "=" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "*" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "|" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "-" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = ";" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = ":" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute Replace:=wdReplaceAll > End Sub
Answered in at least two other newsgroups. Please do not multipost. -- 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. wrote in message news:k18rv1pfk78ubmgt4grc1oj5j5g40psbrc@4ax.com... >I recorded and edited this macro to remove unwanted characters from a > word 2003 document. It does what I wanted and allows me to add or > change the characters as needed, but it seems the code is very > redundent and probably could be shortened to accomplish the same > results. Any help on this would be very much appreciated. Thanks in > advance. Joe > > _________________________________________________________ > > Sub Macro1() > ' > ' Macro1 Macro > ' Macro recorded 8/14/2005 by Joe Payne > ' > Selection.Find.ClearFormatting > Selection.Find.Replacement.ClearFormatting > With Selection.Find > .Text = "?" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute Replace:=wdReplaceAll > Selection.Find.Execute > Selection.Find.ClearFormatting > Selection.Find.Replacement.ClearFormatting > With Selection.Find > .Text = "/" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "+" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = ">" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "@" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = ")" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "(" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "~" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "%" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "#" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "$" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "=" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "*" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "|" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = "-" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = ";" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.Execute Replace:=wdReplaceAll > With Selection.Find > .Text = ":" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute Replace:=wdReplaceAll > End Sub