我的VBA并没有拉动我保存的电子邮件模板的正文

时间:2014-12-09 14:21:47

标签: excel-vba vba excel

我将保存的电子邮件模板的正文拉入我的VBA时遇到了一些困难。我正在使用Office 2010.我正在做的是从Excel发送大量电子邮件。每次我发送它都会收到一封没有正文的空白电子邮件。我有这个与2013年合作。编码年代之间有什么不同吗?

Private Function GetRichTextTemplate() As String

Dim OLF As Outlook.MAPIFolder
Dim olMailItem As Outlook.MailItem

Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)
Set oItems = OLF.Items

For Each Mailobject In oItems
    If Mailobject.subject = "2014 Year End Client Letter" Then
        GetRichTextTemplate = Mailobject.HTMLBody
        Exit Function
    End If
Next

结束功能

1 个答案:

答案 0 :(得分:1)

对于Outlook / VBA,我不是专家,但是我必须努力表明主题被找到并且前进到下一行GetRichTextTemplate = Mailobject.HTMLBody是这样的:

Private Function GetRichTextTemplate() As String

Dim OLF As Outlook.MAPIFolder
Dim olMailItem As Outlook.MailItem

Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set oItems = OLF.Items

For Each olMailItem In OLF.Items

    i = i + 1
    With OLF.Items(i)

    If .Subject = "2014 Year End Client Letter" Then
        GetRichTextTemplate = mailobject.HTMLBody
        Exit Function
    End If

    End With

Next

End Function