S
snsd
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
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