通过电子邮件将选择从Excel发送为附件

时间:2016-11-08 10:15:50

标签: excel vba outlook

我正在使用此宏将工作簿作为附件发送(Book1.xlsx)

Sub Macro2_SendByEMail()

' Copy the sheet(1)
ThisWorkbook.Sheets(1).Copy

' Send Email
With ActiveWorkbook
.SendMail Recipients:=Array("address@company.com", "address2@company"), Subject:="Addresses [" & Format(Date, "dd/mm/yy") & "]"
.Close SaveChanges:=False
End With

End Sub

但我无法找到如何编辑代码,以便仅发送工作簿的前三列 ......

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

你可以尝试一下:

Option Explicit

Sub Macro2_SendByEMail()

' Copy the sheet(1)
    Dim my_range    As Range
    Dim l_row       As Long

    l_row = ThisWorkbook.Sheets(1).UsedRange.Rows.Count
    With ThisWorkbook.Sheets(1)
        Set my_range = .Range(.Cells(1, 1), .Cells(l_row, 3))
    End With

    my_range.Copy

    ' Send Email
    With ActiveWorkbook
    .SendMail Recipients:=Array("address@company.com", "address2@company"), Subject:="Addresses [" & Format(Date, "dd/mm/yy") & "]"
    .Close SaveChanges:=False
    End With

End Sub

我们的想法是在第一张纸中取出使用范围的最后一行,然后根据它定义要复制的选择。