我正在使用以下代码将表粘贴在Outlook上的新电子邮件中:
'Copy range of interest
Dim r As Range
Set r = Range("B2:D5")
r.Copy
'Open a new mail item
Dim outlookApp As Outlook.Application
Set outlookApp = CreateObject("Outlook.Application")
Dim outMail As Outlook.MailItem
Set outMail = outlookApp.CreateItem(olMailItem)
'Get its Word editor
outMail.Display
Dim wordDoc As Word.Document
Set wordDoc = outMail.GetInspector.WordEditor
'To paste as picture
wordDoc.Range.PasteAndFormat wdChartPicture
'To paste as a table
'wordDoc.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
,但是我需要在粘贴表之前写一条消息。我已经尝试使用这些参数:
With OutMail
.To = ThisWorkbook.Sheets("Sheet2").Range("C1").Value
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = "This is an e-mail"
' In place of the following statement, you can use ".Display" to
' display the e-mail message.
.Display
End With
但是,当表粘贴表时,它覆盖.htmlbody参数。
bellow我正在使用的整个代码:
Sub btn_Copiar_Clique()
'Range("B2:L44").Select
Dim r As Range
Set r = Range("A2:L44")
r.Copy
'Open a new mail item
Dim outlookApp As Outlook.Application
Set outlookApp = CreateObject("Outlook.Application")
Dim outMail As Outlook.MailItem
Set outMail = outlookApp.CreateItem(olMailItem)
'Get its Word editor
outMail.Display
Dim wordDoc As Word.Document
Set wordDoc = outMail.GetInspector.WordEditor
'To paste as picture
'wordDoc.Range.PasteAndFormat wdChartPicture
With outMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Relatório de Captação de Fundos - Private"
.HTMLBody = "Boa tarde," & "<br>" & "Segue relatório de captação dos fundos vendidos no private." & "<br>"
'You can add other files also like this
'.Attachments.Add ("C:test.txt")
.Display 'or use .Display
'.Send
End With
'To paste as a table
wordDoc.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
End Sub
查看wordDoc.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
是在参数.HTMLBody
之后。这使得粘贴代码覆盖参数 .HTMLBody
。
我正在使用这些库:Microsoft Office 16.0对象库Microsoft Outlook 16.0对象库 *这是需要的Microsoft Word 16.0对象库 *这是需要
粘贴后,在现有的.htmlbody上添加上方:
.HTMLBody = "text" & .HTMLBody
您已经在使用.Display
,因此不需要第二个,请保持以下
'Get its Word editor outMail.Display Dim wordDoc As Word.Document Set wordDoc = outMail.GetInspector.WordEditor
添加 HTMLBody
使用 insertParagraphafter方法 emampe
With outMail .To = "" .cc = "" .BCC = "" .Subject = "Relatório de Captação de Fundos - Private" .HTMLBody = "Boa tarde," & "<br>" & "Segue fundos vendidos no private." wordDoc.Range.InsertParagraphAfter wordDoc.Paragraphs(2).Range.PasteAndFormat wdChartPicture End With
要添加一些内容,请参见示例
wordDoc.Range.InsertParagraphAfter wordDoc.Paragraphs(2).Range.PasteAndFormat wdChartPicture wordDoc.Range.InsertParagraphAfter wordDoc.Range.InsertAfter "bla bla"
使用WordDoc.Paragraph(3(在" bla bla"之后的行中。