我编写了一个宏来自动发送邮件正文中的一系列Excel工作表,并添加另一个工作表范围作为附件。当我运行它时,它表示附件所在的行中存在错误(无效的过程或调用参数)。我提供以下代码。
错误行
.Item.attachments.Add (Sheets("New Report").Range("A1:X93").Text)
整个代码
Sub EmailsNewReport()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim ToArray As String
Dim CCArray As String
Dim Subject As String
Dim Content As String
Sheets("New Report").Select
ToArray = "feliagkas.pg@pg.com"
Subject = "Hello"
Content = "Hey"
Sheets("New Report").Range("B3:P31").Select
ActiveWorkbook.EnvelopeVisible = True
With Sheets("New Report").MailEnvelope
.Introduction = Content
.Item.To = ToArray
.Item.Subject = Subject
.Item.attachments.Add (Sheets("New Report").Range("A1:X93").Text)
.Item.Send
End With
Application.DisplayAlerts = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub