[英]VBA macro to copy and paste range into email
嗨,我有一个宏,可以创建PDF,然后创建电子邮件并发送pdf。 现在,我需要复制一系列单元格并将其粘贴到电子邮件正文中。 我已经看到了复制和粘贴宏的示例,但不知道如何将代码组合到创建和发送宏中。
任何帮助表示赞赏
谢谢
谢谢-这是当前代码
这是来自rondebruin.nl(进行了一些编辑)。
Sub new_save_as()
Dim OlApp As Object
Dim NewMail As Object
Dim TempFilePath As String
Dim TempFileName As String
Dim FileFullPath As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
TempFilePath = Environ$("temp") & "\"
TempFileName = "Rewards desk report" & " " & Format(Now - 1, "dd-mmm-yy") & ".pdf"
FileFullPath = TempFilePath & TempFileName
On Error GoTo err
With ActiveSheet
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=FileFullPath, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
Set OlApp = CreateObject("Outlook.Application")
Set NewMail = OlApp.CreateItem(0)
On Error Resume Next
With NewMail
.To = "address here"
.CC = "address here"
.BCC = ""
.Subject = "Rewards desk daily report"
.Body = "The daily report is attached"
.Attachments.Add FileFullPath
.Display
End With
On Error GoTo 0
Kill FileFullPath
Set NewMail = Nothing
Set OlApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox ("Email has been Sent Successfully")
Exit Sub
err:
MsgBox err.Description
End Sub
您要复制/粘贴的范围的性质是什么? 如果内容太短,请考虑将其设置为变量。
msg1 = Range("A1").Value
msg2 = Range("A2").Value
msg3 = Range("A3").Value
然后将您的代码更改为
.Body = "The daily report is attached" & vbCrLf & msg1 & " " & msg2 & " " & msg3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.