将附件作为相对路径上载到Outlook

时间:2015-01-22 18:51:54

标签: excel vba excel-vba outlook

我有代码创建工作表的PDF并将其保存到相对路径。我然后尝试将该PDF上传到显示(不发送)的电子邮件。当我点击一个按钮(我已经指定了一个宏来将两个宏运行到这个按钮)时,我希望这一切都能立即发生。

但是,我无法让附件工作。是否可以将附件保存为相对路径?我这样做是因为代码需要标准化,所以我可以通过复制和粘贴在很多电子表格中使用它。

我用于电子邮件的具体代码如下。

On Error Resume Next
    With OutMail 'Todos dados do email
        .to = ""
        .CC = ""
        .BCC = ""
        .Subject = "" & CompanyName & " - Invoice - " & Data & ""
        .Body = "Dear ," & Chr(10) & Chr(10) & "Please, find enclosed the invoices regarding the (COLOQUE ACORDO AQUI) between our companies."
        .Attachments.Add        'Adicionar Attachments
        '.Attachments.Add ("C:\test.txt")
        .Display   '.Display para mostrar o email
    End With

1 个答案:

答案 0 :(得分:0)

微软建议这样做。

Dim myItem As Outlook.MailItem 
Dim myAttachments As Outlook.Attachments 

 Set myItem = Application.CreateItem(olMailItem) 
 Set myAttachments = myItem.Attachments 
 myAttachments.Add "C:\Test.doc", _ 
 olByValue, 1, "Test" 
 myItem.Display 

见这里:Attachments.Add Method