在Outlook中粘贴表格之前写入-Excel VBA [英] Write before paste table in Outlook - Excel VBA

查看:411
本文介绍了在Outlook中粘贴表格之前写入-Excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在Outlook的新电子邮件中粘贴表格:

I'm using the following code to paste a table in a new email on 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

但是我需要在粘贴表之前写一条消息. 我已经尝试使用参数:

But I need to write a message before the pasted table. I already tried to use the parameters:

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参数.

But when paste the table it overwrites the .HTMLBody parameter.

请注意我正在使用的全部代码:

Bellow the entire code that I'm using:

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.

Look that the wordDoc.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False is after the parameter .HTMLBody. That makes the pasting code overwrite the parameter .HTMLBody.

我正在使用以下库: Microsoft Office 16.0对象库 Microsoft Outlook 16.0对象库*这是必需的 Microsoft Word 16.0对象库*这是必需的

I'm using these libraries: Microsoft Office 16.0 Object Library Microsoft Outlook 16.0 Object Library *This is needed Microsoft Word 16.0 Object Library *This is needed

推荐答案

粘贴后,在现有.HTMLBody上方添加:

After a paste, to add above an existing .HTMLBody:

.HTMLBody = "text" & .HTMLBody

这篇关于在Outlook中粘贴表格之前写入-Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆