我尝试做的是循环发送一封电子邮件给一个列表中的人,每个人都收到自己的excel文件。第一部分还没有设置,所以我有占位符的信息,谁去,但我有附件的问题。该程序没有附件行工作正常,但当我添加,我得到了前面提到的错误,我难倒如何修复它。
Sub AttachAndEmail()
Dim fileDirectory As String
Dim fileCriteria As String
Dim fileName As String
Dim emailApplication As Object
Dim emailItem As Object
On Error Resume Next
Set emailApplication = GetObject(, "Outlook.Application")
If Err.Number > 0 Then Set emailApplication = CreateObject("Outlook.Application")
Set emailItem = emailApplication.CreateItem(0)
On Error GoTo 0
Application.ScreenUpdating = False
fileDirectory = "C:\Users\DW1085\Downloads\a\"
fileName = Dir(fileDirectory)
Do While Len(fileName) > 0
emailItem.to = "Myname@email.com"
emailItem.Subject = "WowweWow"
emailItem.Body = "Yup"
emailItem.Attachments.Add fileName
emailItem.Display
fileName = Dir
Loop
Application.ScreenUpdating = True
End Sub
1条答案
按热度按时间hlswsv351#
Attachments.Add方法在
Attachments
集合中创建一个新附件。附件的源可以是一个文件(由带有文件名的完整文件系统路径表示),也可以是构成附件的Outlook项目。因此,您需要传递要附加的文件的完整路径。例如: