我的问题:
有没有办法复制单元格范围并以编程方式将其粘贴到Outlook邮件正文中?
我有这个代码,但它似乎没有复制单元格范围,但是如果你输入一个单独的单元格(例如A4),它就可以复制它。
Sub Email()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim szTodayDate As String
szTodayDate = Format(Date, "mm.dd.yyyy")
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = ActiveSheet.Range("A4:B4").Value
On Error Resume Next
With xOutMail
.To = "tryemail@gmail.com"
.CC = "tryemail2@gmail.com"
.BCC = ""
.Subject = "Schedule for deal pursuit" & " " & szTodayDate
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
答案 0 :(得分:0)
这是我唯一的想法..使用循环将每个单元格值添加到bodyMail ..
xMailBody = ""
' i represents the columns
For i = 1 To 2
xMailBody = xMailBody & " " & ActiveSheet.Cells(4, i).Value
Next i