为什么Msgbox会显示问号而不是文本正文中出现的空格? [英] 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
某些传入的邮件(国外和国内)内容在Outlook中看起来不错,但是当我运行上述宏程序时,消息框(可变文本体)显示的是单词之间带有问号的文本,而不是空格.
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.
为了举例说明,
-
Outlook Mail读取:
Outlook Mail reads:
你好,你好吗?
Msgbox显示:
Msgbox shows:
你好吗?你在做什么?
Hello?there?how?are?you?doing?
似乎字符没有正确存储在变量中.以下测试代码的第一个 instr()
结果为"0",而后面的代码部分的结果为> 0".似乎文本正文中的问号会阻止正确检测字符串中连续匹配的单词.
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
推荐答案
没有示例,我不能给出绝对的答案,但是问号很可能将Unicode字符(主要是您的外来字符)表示为?
,因为 Unicode无法以 MsgBox
所使用的字体呈现.
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 [微笑]
...将在 MsgBox
中呈现为:
...will render in the MsgBox
as:
Smiley Face [?] Smile in Chinese [??]
如果尝试使用 Debug.Print
在立即窗口中显示它,则同样如此.
The same goes if you try to display it in the Immediate Window with Debug.Print
.
但是,正确的字符存储在 String
中.例如,如果您要以编程方式将值放入Excel单元格,则可能会正确显示:
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:
话虽如此,我确信Windows/Office的区域版本可以正确显示Unicode字符,否则,永远不会在消息框中显示外来符号.
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.
一种解决方法是将默认消息框字体更改为支持Unicode的字体.
A workaround may be to change the default message box font to one that supports Unicode.
这篇文章也可能会有所帮助:
This article may also be helpful:
这篇关于为什么Msgbox会显示问号而不是文本正文中出现的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!