MailItem.GetInspector.WordEditor returns Nothing

房东的猫 提交于 2021-01-29 05:23:00

问题


I'm composing an email using VB.Net which is opened in Outlook 2013. I need to the contents to be displayed in its default font which is set by the user.

Now i need to get the default font and set to the email. When i tried it returns null at one place.

//Code:

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

Where am i wrong? Any help?

Source


回答1:


WordEditor property might not be available until the message is shown.

Try to simply set the MailItem.HTMLBody property.



来源:https://stackoverflow.com/questions/38119333/mailitem-getinspector-wordeditor-returns-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!