来自Excel的电子邮件不会发送附件

我有一个工作簿,我从中创build一个基于一系列单元格的PDF。 这一切工作正常。 我这样做与产生电子邮件分开,所以可以在其发送电子邮件之前进行检查。 然后,我从同一个工作簿创build一个电子邮件发送PDF附件。 电子邮件的正文是从工作簿的另一个单元格范围创build的。 再一次,这样做没有问题。 我发送的时候出现了问题。 电子邮件发送罚款和电子邮件的正文是好的,但没有附件。

我已经尝试三重检查附件的文件path(甚至将其移动到一个更简单的path进行testing),并将其更改为附加一个简单的文档文件。 我也使用了两个不同的电子邮件提供商1和1和GMail,但也有同样的问题。 那个依恋只是不想离开我。

我也注意到,当我将鼠标hover在任何types的链接上时,我现在都有一条鼠标指针出现的消息。 消息是:处理请求时出错 – 错误的响应。 我只能猜测它与我已经发射的所有testing邮件有关,但不知道它是什么意思或如何摆脱它。 我还有东西在跑吗?

Sub CDO_Send_Email_Angebot() Dim Rng As Range Dim iMsg As Object Dim ws As Worksheet Dim Flds As Variant Dim iConf As Object Dim PdfFile As String PdfFile = Sheets("5_Angebot").Range("E97").Value & "." & Sheets("5_Angebot").Range("E98").Value 'MsgBox rngAttachment '---------- Get the Emails from a cells on the sheet Dim SendItTo As String Dim SenderEmail As String Dim Subjectext As String SendItTo = Sheets("5_Angebot").Range("E94").Value SenderEmail = Sheets("5_Angebot").Range("E95").Value SubjectText = Sheets("5_Angebot").Range("E96").Value '--------- Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") iConf.Load -1 ' CDO Source Defaults Set Flds = iConf.Fields With Flds .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = SenderEmail '.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "**********" '.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.1and1.com" .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "***********" .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Update End With ' ------ With Application .ScreenUpdating = False .EnableEvents = False End With Set Rng = Nothing On Error Resume Next Set Rng = Selection.SpecialCells(xlCellTypeVisible) Set Rng = Sheets("5_Angebot").Range("C101:J121") Set iMsg = CreateObject("CDO.Message") With iMsg Set .Configuration = iConf .To = SendItTo .From = SenderEmail .Subject = SubjectText .HTMLBody = RangetoHTML(Rng) '.Attachments.Add PdfFile .Attachments.Add ("D:\Corinne\test.docx") .Send End With Set iMsg = Nothing ' -------- With Application .EnableEvents = True .ScreenUpdating = True End With End Sub 

快速谷歌searchbuild议适当的方法是AddAttachment ,而不是Attachments.Add (后者是为MS Outlook)。 在你的方法调用中可能还有其他错误,所以我上面的build议仍然存在:debugging没有 On Error Resume Next