【问题标题】:Sending emails with attachment using VBA使用 VBA 发送带附件的电子邮件
【发布时间】:2020-10-05 22:21:59
【问题描述】:

我想通过 Outlook 自动发送电子邮件。它到达myAttachments.Add 并声明:

对象不支持此属性或方法。

我尝试了几种不同的方法,但附件部分仍然出现错误。所有其他部分都可以创建电子邮件。

我做错了什么?

Sub Send_Emails()

    Dim OutlookApp As Outlook.Application
    Dim OutlookMail As Outlook.MailItem
    Dim myAttachments As Outlook.Attachments

    Set OutlookApp = New Outlook.Application
    Set OutlookMail = OutlookApp.CreateItem(olMailItem)
    Set myAttachments = OutlookMail.Attachments
    
    myAttachments.Add Source:=ThisWorkbook, Type:=olByValue
  
    With OutlookMail
        .BodyFormat = olFormatHTML
        .HTMLBody = "Attached is the Transaction Report"
        .To = "email@yahoo.com"
        .Subject = "Transaction Report"
        .Send
    End With
    
End Sub

【问题讨论】:

    标签: vba outlook


    【解决方案1】:
    With OutlookMail
        
        .To = "email@nowherenoplace.com"
        
        .Attachments.Add ThisWorkbook.fullName
        
        .Display
    
    End With
    

    【讨论】:

      猜你喜欢
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 2016-10-23
      • 2012-01-15
      • 1970-01-01
      相关资源
      最近更新 更多