Reputation: 151
dim oEmail As Outlook.mailitem
dim textbody as string
textbody = oEmail.body
msgbox textbody
Some incoming mail (foreign and domestic) contents appear fine in Outlook, but when I run the above macro program, the message box (variable textbody) shows text with question marks between words, instead of spaces.
To illustrate with example,
Outlook Mail reads:
Hello there how are you doing?
Msgbox shows:
Hello?there?how?are?you?doing?
It seems that characters are not stored properly in the variable.
The following test code results in "0" for the first instr()
, while the latter code part results in ">0". It seems the question marks in the text body prevent proper detection of consecutive matching words in the string.
if InStr(1, LCase$(textbody), "how are you") > 0 Then
msgbox "found 3 consecutive matching words in string"
end if
if InStr(1, LCase$(textbody), "how") > 0 Then
msgbox "found a word match in string"
end if
Upvotes: 0
Views: 1630
Reputation: 21639
Without a sample, I can't give an absolute answer, but most likely the question marks are representing Unicode Characters (so mostly your foreign characters) as ?
since Unicode cannot be rendered in the font that is used by the MsgBox
.
For example, an email that contains this:
Smiley Face [☺] Smile in Chinese [微笑]
...will render in the MsgBox
as:
Smiley Face [?] Smile in Chinese [??]
The same goes if you try to display it in the Immediate Window with Debug.Print
.
However, the correct characters are stored in the String
. For example, if you were to programmatically put the value into an Excel cell, it would likely display properly:
That being said, I'm sure that regional versions of Windows/Office can properly display Unicode characters, or else foreign symbols could never be displayed in message boxes.
A workaround may be to change the default message box font to one that supports Unicode.
This article may also be helpful:
Upvotes: 1