VBA求助:如何复制excel表格到outlook邮件?
以下是我现在用的语句。Range("A1:F"&Cells(Rows.Count,1).End(3).Row)是Excel表格里的一个范围,我要将这个范围是一个表格,我要...
以下是我现在用的语句。Range("A1:F" & Cells(Rows.Count, 1).End(3).Row)是Excel表格里的一个范围,我要将这个范围是一个表格,我要将这个表格用outlook的email发送给某人。如下语句Display时MailSubject没有问题,但是这个表格始终不能显示。请高人赐教。
Dim OutApp As Object
Dim OutMail As Object
Dim MailBody
Dim MailSubject As String
MailBody = Range("A1:F" & Cells(Rows.Count, 1).End(3).Row)
MailSubject = Range("G2")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
On Error Resume Next
With OutMail
.To = "abc@163.com"
.cc = ""
.BCC = ""
.Subject = MailSubject
.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
.HTMLBody = MailBody
.Display
End With
On Error GoTo 0 展开
Dim OutApp As Object
Dim OutMail As Object
Dim MailBody
Dim MailSubject As String
MailBody = Range("A1:F" & Cells(Rows.Count, 1).End(3).Row)
MailSubject = Range("G2")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
On Error Resume Next
With OutMail
.To = "abc@163.com"
.cc = ""
.BCC = ""
.Subject = MailSubject
.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
.HTMLBody = MailBody
.Display
End With
On Error GoTo 0 展开
展开全部
1、点新建。
2、光标定位在正文区,点插入菜单——表格,选择行*列表格,例如:2*3表格。
3、复制相同单元格数的excel。
Microsoft Office Outlook是微软办公软件套装的组件之一,它对Windows自带的Outlook express的功能进行了扩充。Outlook的功能很多,可以用它来收发电子邮件、管理联系人信息、记日记、安排日程、分配任务。目前最新版为Outlook 2016。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
插入一个模块,然后复制粘贴以下语句,然后将你的语句里的.HTMLBody = MailBody改为.HTMLBody = RangetoHTML(MailBody)即可。
Public Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
TempWB.Close savechanges:=False
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
Public Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
TempWB.Close savechanges:=False
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我来帮你实现vba
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询