我已经编写了复制excel值的代码,现在我要做的就是将该范围粘贴到我的电子邮件正文中。我不确定如何粘贴它。谢谢大家的时间。我试图创建另一个" msg"与selection.Paste,但它错了。
Sub Send_Emails()
Dim OutApp As Object: Set OutApp = CreateObject("Outlook.Application")
Dim OutMail As Object: Set OutMail = OutApp.CreateItem(0)
Dim msg1 As String
Dim msg2 As String
Dim msg3 As String
Dim msg4 As String
Dim msg5 As String
msg1 = "Hi" & " " & ActiveCell.Offset(0, 4).Value & "," & " " & "<br>" & "<br>"
msg2 = " I am reaching out to schedule"
msg3 = Range(ActiveCell, Selection.End(xlDown).Offset(-1, 0)).Offset(0, 1).Select
Selection.Copy
msg4 = " What dates and times work best for you or others?"
With OutMail
.To = ActiveCell.Offset(0, 2).Value
.CC = ActiveCell.Offset(0, 3).Value
.Subject = "Update Request"
.HTMLbody = msg1 & msg2 & msg3.Selection.Paste & msg4
.Display
End With
On Error Resume Next:
OutMail = Nothing
OutApp = Nothing
End Sub
答案 0 :(得分:0)
这条线
msg3 = Range(ActiveCell, Selection.End(xlDown).Offset(-1, 0)).Offset(0, 1).Select
没有意义。您需要将.Value
设置为变量
msg3 = Range(ActiveCell, Selection.End(xlDown).Offset(-1, 0)).Offset(0, 1).Value
然后您无需复制Selection.Copy
删除该内容。
您无需粘贴:
.HTMLbody = msg1 & msg2 & msg3.Selection.Paste & msg4
而只是使用变量
.HTMLbody = msg1 & msg2 & msg3 & msg4
我建议阅读一些关于如何使用单元格中的变量和值来学习一些基本编程技巧的好教程。