snsd
Fri Aug 04 11:34:02 CDT 2006
Greg: Thanks for the suggestion. VERY close to working. I think the ' ^13- is
the challenge. I'm assuming that is an attempt to identify a '. When I take
it out and use your suggestion, all works perfectly except that the ' gets
removed when it shouldn't.
What should be put in to leave ' in the list?
Thanks,
Dave
"Greg Maxey" wrote:
> I didn't test the code, but part of the problem is explained by using
> !A-z.
>
> !A-z would be expected to exclude all the letters between A and z i.e.
> both upper case and lower case letters, which it does, but it excludes
> all the characters in the ASCII 65 to ASCII 122 range, and that block
> includes the characters [ ] ` ^ _ /.
>
> Use !A-Za-z instead.
>
> snsd wrote:
> > Thanks Dave. Sincerely appreciated. I tried your code as follows. (I am NOT a
> > programmer so don't entirely understand the logic of what you've done.)
> >
> > Sub ReplaceList()
> >
> > With Selection
> > .HomeKey Unit:=wdStory
> > With .Find
> > .ClearFormatting
> > .MatchWildcards = True
> > .Text = "[!A-z0-9/:/(/)+.,' ^13-\?]"
> > With .Replacement
> > .ClearFormatting
> > .Text = ""
> > End With
> >
> > .Execute Replace:=wdReplaceAll
> > End With
> > End With
> >
> > End Sub
> >
> > The only characters outside of my list that it removed were ~, @ and {}. It
> > didn't remove any other characters that I would have expected it to. Any idea
> > as to why that might be happening?
> >
> > Thanks,
> >
> > Dave
> >
> > "Dave Lett" wrote:
> >
> > > Hi,
> > >
> > > The following works on my machine.
> > >
> > > With Selection
> > > .HomeKey Unit:=wdStory
> > > With .Find
> > > .ClearFormatting
> > > .MatchWildcards = True
> > > .Text = "[!A-z0-9/:/(/)+.,' ^13-\?]"
> > > With .Replacement
> > > .ClearFormatting
> > > .Text = ""
> > > End With
> > >
> > > .Execute Replace:=wdReplaceAll
> > > End With
> > > End With
> > >
> > > HTH,
> > > Dave
> > >
> > > "snsd" <snsd@discussions.microsoft.com> wrote in message
> > > news:33E58823-5018-4CAA-A2CF-D06C23CD11FE@microsoft.com...
> > > > Thanks to all of you for your excellent responses. They were all very
> > > > helpful
> > > > - and they work! I have one more question that I should have thought of
> > > > beforehand. I'm assuming it's a simple adjustment to the code. I've
> > > > realized
> > > > that rather than having a list of INVALID characters, it would be simpler
> > > > to
> > > > have a list of VALID characters. The valid characters are:
> > > >
> > > > ABCDEFGHIJKLMNOPQRSTUVWXYZ
> > > > abcdefghijklmnopqrstuvwxyz
> > > > 0123456789
> > > > /:-?()+.,'
> > > >
> > > > So, I would like to remove any characters that do NOT match the above
> > > > characters. I realized that when you get into all the non-keyboard
> > > > characters...that my list would be very difficult to manage. Any help in
> > > > modifying the code to replace all characters NOT matching the above would
> > > > be
> > > > great.
> > > >
> > > > Thanks,
> > > >
> > > > Dave
> > > >
> > > > "Graham Mayor" wrote:
> > > >
> > > >> The following will replace a list of characters each in quotes and
> > > >> separated
> > > >> by commas as below with a green highlighted space:
> > > >>
> > > >> Sub ReplaceList()
> > > >> Dim vFindText As Variant
> > > >> Dim sReplText As String
> > > >> Dim sHighlight As String
> > > >> Dim i As Long
> > > >>
> > > >> sHighlight = Options.DefaultHighlightColorIndex
> > > >> Options.DefaultHighlightColorIndex = wdBrightGreen
> > > >> vFindText = Array("*", "&", "$", "%", "#")
> > > >> sReplText = " "
> > > >> With Selection.Find
> > > >> .Forward = True
> > > >> .Wrap = wdFindContinue
> > > >> .MatchWholeWord = True
> > > >> .MatchWildcards = False
> > > >> .MatchSoundsLike = False
> > > >> .MatchAllWordForms = False
> > > >> .Format = True
> > > >> .MatchCase = True
> > > >> For i = LBound(vFindText) To UBound(vFindText)
> > > >> .Text = vFindText(i)
> > > >> .Replacement.Text = sReplText
> > > >> .Replacement.Highlight = True
> > > >> .Execute replace:=wdReplaceAll
> > > >> Next i
> > > >> End With
> > > >> Options.DefaultHighlightColorIndex = sHighlight
> > > >> End Sub
> > > >>
> > > >>
> > > >> --
> > > >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> > > >> Graham Mayor - Word MVP
> > > >>
> > > >> My web site www.gmayor.com
> > > >> Word MVP web site
http://word.mvps.org
> > > >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> > > >>
> > > >> snsd wrote:
> > > >> > Hi:
> > > >> >
> > > >> > There is a financial messaging service known as SWIFT. SWIFT does not
> > > >> > allow the usage of certain characters in its messages. I am
> > > >> > attempting to create some code that will strip a Word document of the
> > > >> > invalid characters - and preferably replace the invalid character
> > > >> > with a highlighted space so the user can easily identify what the
> > > >> > document will look like without the invalid characters. The following
> > > >> > code successfully removes the "*" character from my document. I would
> > > >> > like to modify the code so that it will search for a list of other
> > > >> > characters such as &, $, %, #, etc. and remove them from the document
> > > >> > as well. Ideally, I would like the space where the character was
> > > >> > removed to be highlighted so the user can see where the character was
> > > >> > removed. (I am fine replacing the character with the "space"
> > > >> > character.) Is there a way to search for and replace multiple
> > > >> > characters without having to repeat the code multiple times? I
> > > >> > haven't done a lot of programming in Word - but have a basic
> > > >> > understanding of VBA in an Access environment. Any help would be
> > > >> > greatly appreciated.
> > > >> >
> > > >> > Thanks,
> > > >> >
> > > >> > Dave
> > > >> >
> > > >> > (The following code was created using the macro recorder in Word.)
> > > >> >
> > > >> > Sub RemoveInvalidISO15022characters()
> > > >> > ' Removes Invalid ISO15022 characters from document
> > > >> >
> > > >> > 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
> > > >> > End Sub
> > > >>
> > > >>
> > > >>
> > >
> > >
> > >
>
>