通过电子邮件将所选单元格作为Excel VBA中的多个附件发送

时间:2019-05-21 17:55:28

标签: excel vba

我在Excel中有一些非常基本的VBA代码,可以从活动单元格中创建电子邮件-该单元格包含附件的整个文件路径。有没有一种方法可以选择多个单元格(每个单元格具有不同的文件路径)并基于所选单元格创建包含多个附件的电子邮件?

我尝试替换代码以使用“选择”,但始终出现错误。

Sub Send_email_fromexcel()
Dim edress As String
Dim subj As String
Dim message As String
Dim filename As String
Dim outlookapp As Object
Dim outlookmailitem As Object
Dim myAttachments As Object
Dim path As String
Dim lastrow As Integer
Dim attachment As String
Dim rngAttach As Range

    Set outlookapp = CreateObject("Outlook.Application")
    Set outlookmailitem = outlookapp.createitem(0)
    Set myAttachments = outlookmailitem.Attachments
    path = ActiveCell
    attachment = path
        outlookmailitem.Subject = subj
        myAttachments.Add (attachment)
        outlookmailitem.display
        Set outlookapp = Nothing
Set outlookmailitem = Nothing

End Sub

我怀疑我必须指定范围号并编写条件语句,但是我不太确定,因为我的vba编码有点不稳定。

1 个答案:

答案 0 :(得分:0)

对于那些好奇的人:

objectWasHit = whatObjectHit.collider.gameObject;