0
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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Barok
  • 151
  • 1
  • 15

1 Answers1

1

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:

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • Thank you for your comments. But I am afraid it is not a display issue. – Barok Apr 10 '18 at 04:23
  • @Barok - My examples work just fine for me. MsgBox's (at least here) can't display Unicode. If this isn't the problem then you mis-worded the question. Have you tried any of my examples, like how the characters display properly when placed (programmatically) into an Excel cell? If characters are not displaying how you want them to, i s, *by definition* a "display issue"; I suspect you're not following my explanation. Question marks are used in place of characters that cannot be displayed, for "whatever" reason; that's standard. Basically, the problem is that you're using a `MsgBox`. – ashleedawg Apr 10 '18 at 04:26