【发布时间】:2023-01-24 03:06:20
【问题描述】:
我正在尝试从 Excel 发送电子邮件,该电子邮件使用保存在 A2 数据表中的数据透视表范围发送附件,并且每天都是动态的。
在 .TO 字段我得到错误
对象不支持此方法。
Sub emailtest() Dim objOutlook As Object Dim objMail As Object Dim rngTo As String Dim rngSubject As String Dim rngBody As String Dim LastRow As Long Set objOutlook = CreateObject("Outlook.Application") Set objMail = objOutlook.CreateItem(0) Sheets("Data").Select LastRow = Worksheets("Data").Range("A" & Rows.Count).End(xlUp).Row With objMail .To = Worksheets("Data").Range("A2: A" & LastRow - 1) .Subject = "Sell Fail Trade" .Body = "Please find today's sell report" .Attachments.Add "C\Temp Folder" .Display 'Instead of .Display, you can use .Send to send the email _ or .Save to save a copy in the drafts folder End With Set objOutlook = Nothing Set objMail = Nothing End Sub
【问题讨论】: