2016-06-30 120 views
0

我使用VB.Net撰寫郵件,該郵件在Outlook 2013中打開。我需要將內容以其由用戶設置的默認字體顯示。MailItem.GetInspector.WordEditor返回Nothing

現在我需要獲取默認字體並設置爲電子郵件。當我嘗試它在一個地方返回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

回答

0

WordEditor屬性可能不可用。

試着簡單地設置MailItem.HTMLBody屬性。

+0

我需要獲取用戶在撰寫電子郵件期間設置的默認字體。現在全部默認爲TimesNewRoman。何處/如何獲取默認字體? – iamCR

+0

爲什麼不在設置HTMLBody時明確指定正確的字體? –

+0

正確的字體是用戶定義的字體。所以我需要從Outlook中的某處獲取它(如代碼中所示)。 – iamCR

相關問題