在将Excel中的表格复制到Outlook邮件正文之前,先将表格复制到剪贴板。代码示例:
Dim objExcel
As
Object
Dim objWorkbook
As
Object
Dim objWorksheet
As
Object
'打开Excel文件并选定工作表
Set objExcel = CreateObject("Excel.Ap
pl
ication")
Set objWorkbook = objExcel.Workbooks.Open("C:\exam
pl
e.xlsx")
Set objWorksheet = objWorkbook.Sheets("Sheet1")
'将表格复制到剪贴板
objWorksheet.Range("A1:C4").Copy
'创建Outlook邮件并将表格粘贴到正文中
Dim objOutlook
As
Object
Dim objMail
As
Object
Set objOutlook = CreateObject("Outlook.Ap
pl
ication")
Set objMail = objOutlook.CreateItem(olMailItem)
With objMail
.Dis
pl
ay
Set objInsp = .GetInspector
Set objWordEditor = objInsp.WordEditor
objWordEditor.Ap
pl
ication.Selection.P
as
te
End With
'关闭Excel文件和程序
objWorkbook.Close False
objExcel.Quit
Set objExcel = Nothing