Barok
Barok

Reputation: 151

Why does Msgbox display question marks instead of spaces that appear in text body?

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,

  1. Outlook Mail reads:

    Hello there how are you doing?

  2. 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

Answers (1)

ashleedawg
ashleedawg

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:

img

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.

scr


This article may also be helpful:

Upvotes: 1

Related Questions