在电子邮件VBA excel附件

我想在Excel中通过VBA发送电子邮件,所有的作品都很好的尊重电子邮件的附件。 它似乎没有链接它。 问题在哪里? string附加指向正确的文件。

Dim OutApp As Object Dim OutMail As Object Dim email Dim attach email = writeEmailAddress() attach = attachement() Sheets("Mail").Range("B1") = email Sheets("Mail").Range("B2") = "xxxxxx" Sheets("Mail").Range("B3") = "xxxxxxx" Sheets("Mail").Range("B4") = attach MsgBox attach Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .SendKeys "^{ENTER}" .to = "xxxxx" .CC = "" .BCC = "" .Subject = Sheets("Mail").Range("B5").Value .Body = Sheets("Mail").Range("B6").Value 'You can add other files also like this .Attachments.Add attach ' <--------------------------------This is causing troubble .Display End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing 

更改,

 .Attachments.Add attach 

… 至,

 If CBool(Len(Dir(attach, vbNormal))) Then .Attachments.Add attach, 1 '<~~ 1 is olByValue Else Debug.Print "Cannot find '" & attach & "'" End If 

如果附件未添加到您的电子邮件中,请检查VBE的即时窗口(例如Ctrl + G)以获取错误消息。