[英]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.