MailItem.GetInspector.WordEditor返回Nothing

时间:2016-06-30 09:40:27

标签: vb.net outlook ms-office

我正在使用VB.Net撰写一封电子邮件,该电子邮件在Outlook 2013中打开。我需要以用户设置的默认字体显示内容。

现在我需要获取默认字体并设置为电子邮件。当我尝试时,它会在一个地方返回null

//代码:

Private m_valDefaultFontSpec As DefaultFont

Sub GetDefaultFontSpec(Optional blnGetReplyFont As Boolean = False)

    Dim objDoc As Document
    Dim rng As Range
    Dim objDummy As MailItem

    On Error Resume Next

    '  Create a "dummy" mail object,
    Set objDummy = Application.CreateItem(olMailItem)

    '  Get the document object from the current "dummy mail" object.
    Set objDoc = objDummy.GetInspector.WordEditor //returns nothing here

    '  Get the range of the word document object.
    Set rng = objDoc.Range

    '  Get some font properties from the given range.
    With rng
        m_valDefaultFontSpec.Name = .Font.Name
        m_valDefaultFontSpec.Size = .Font.Size
        m_valDefaultFontSpec.Bold = .Font.Bold
        m_valDefaultFontSpec.Color = .Font.Color
        m_valDefaultFontSpec.Italic = .Font.Italic
    End With

    '  Finished with the "dummy" mail, close it.
    objDummy.Close olDiscard

    On Error GoTo 0

End Sub

我哪里错了?有什么帮助吗?

Source

1 个答案:

答案 0 :(得分:0)

在显示消息之前,

WordEditor属性可能不可用。

尝试简单地设置MailItem.HTMLBody属性。