J
Jean-Guy Marcil
I am either too tired to think straight or I am overlooking something
simple here...
Here is the background:
Word 2003.
A document contains some characters that are formatted with the Symbol font
and that were inserted with the Insert Symbol dialog.
The same document also contains "(" that are meaningful.
A macro is looking for those "(" but since AscW(Selection.Text) returns 40
for the "(" and for the Symbol font characters, we need to tell if the
character is really a "(" or not. We do not care what symbol it is, as long
as we can tell the symbol apart from the "(".
So, I came up with this macro using some of the clever code I found from
Klaus Linke:
'_______________________________________
Sub MainMacro()
Dim MyRange As Range
Dim CheckCar As Range
Set MyRange = Selection.Range
For Each CheckCar In MyRange.Characters
If AscW(CheckCar) = 40 Then
If CheckIfSymbol(CheckCar) Then
MsgBox "Ne pas traiter ce caractère."
Else
MsgBox "Traiter cette parenthèse."
End If
End If
Next
End Sub
'_______________________________________
'_______________________________________
Function CheckIfSymbol(MyCar As Range) As Boolean
CheckIfSymbol = False
With Selection.Find
.Text = "[" & ChrW(61472) & "-" & ChrW(61695) & "]"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute
If .Found Then
MsgBox "Ce n'est pas un parenthèse ouvrante"
CheckIfSymbol = True
End If
End With
End Function
'_______________________________________
Basically, I check every character that are selected, if I find that one of
them is a "(", I double check to make sure that it really is a "(" and not a
symbol.
Here is the problem:
With
.Wrap = wdFindStop
in the function, the .Found property is always false, even if a symbol is
currently selected.
If I change
.Wrap = wdFindStop
to
.Wrap = wdFindContinue
Then the .Found property is always true because it always finds the symbol
character in the document, even if it is not in the original selected range.
Why is the Find actually working to tell symbols apart from "(" when doing a
document wide search, but not when checking a specific character?
I have done this before, but not with symbol characters. I remember doing
this to tell if a selected character was a section break or a page break. I
used basically the same kind of code and it worked without any problem. This
isn't working and I cannot tell why! Something to do with wild cards?
Arrrggghhh! I need a coffee!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
simple here...
Here is the background:
Word 2003.
A document contains some characters that are formatted with the Symbol font
and that were inserted with the Insert Symbol dialog.
The same document also contains "(" that are meaningful.
A macro is looking for those "(" but since AscW(Selection.Text) returns 40
for the "(" and for the Symbol font characters, we need to tell if the
character is really a "(" or not. We do not care what symbol it is, as long
as we can tell the symbol apart from the "(".
So, I came up with this macro using some of the clever code I found from
Klaus Linke:
'_______________________________________
Sub MainMacro()
Dim MyRange As Range
Dim CheckCar As Range
Set MyRange = Selection.Range
For Each CheckCar In MyRange.Characters
If AscW(CheckCar) = 40 Then
If CheckIfSymbol(CheckCar) Then
MsgBox "Ne pas traiter ce caractère."
Else
MsgBox "Traiter cette parenthèse."
End If
End If
Next
End Sub
'_______________________________________
'_______________________________________
Function CheckIfSymbol(MyCar As Range) As Boolean
CheckIfSymbol = False
With Selection.Find
.Text = "[" & ChrW(61472) & "-" & ChrW(61695) & "]"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute
If .Found Then
MsgBox "Ce n'est pas un parenthèse ouvrante"
CheckIfSymbol = True
End If
End With
End Function
'_______________________________________
Basically, I check every character that are selected, if I find that one of
them is a "(", I double check to make sure that it really is a "(" and not a
symbol.
Here is the problem:
With
.Wrap = wdFindStop
in the function, the .Found property is always false, even if a symbol is
currently selected.
If I change
.Wrap = wdFindStop
to
.Wrap = wdFindContinue
Then the .Found property is always true because it always finds the symbol
character in the document, even if it is not in the original selected range.
Why is the Find actually working to tell symbols apart from "(" when doing a
document wide search, but not when checking a specific character?
I have done this before, but not with symbol characters. I remember doing
this to tell if a selected character was a section break or a page break. I
used basically the same kind of code and it worked without any problem. This
isn't working and I cannot tell why! Something to do with wild cards?
Arrrggghhh! I need a coffee!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org