关于用vba从outlook发邮件问题 20
请问各位前辈,vba可以将excel表中某部分单元格直接通过新邮件发送到outlook吗。比如sheets("测试").range("a4:b6")。如果可以的话,请给我...
请问各位前辈,vba可以将excel表中某部分单元格直接通过新邮件发送到outlook吗。
比如sheets("测试").range("a4:b6")。如果可以的话,请给我一段示例代码,谢谢! 展开
比如sheets("测试").range("a4:b6")。如果可以的话,请给我一段示例代码,谢谢! 展开
2个回答
展开全部
将你要发送的区域命名,在用以下方法
.HTMLBody = "<HTML><H2>Dear all</H2><br><BODY>" & note & "</BODY></HTML>" + RangetoHTML(rag)
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2007
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"
'Copy the range and create a new workbook to past the data in
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
.DlvrawingObjects.Visible = True
.DlvrawingObjects.Delete
On Error GoTo 0
End With
'Publish the sheet to a htm file
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
'Read all data from the htm file into RangetoHTML
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=")
'Close TempWB
TempWB.Close savechanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
.HTMLBody = "<HTML><H2>Dear all</H2><br><BODY>" & note & "</BODY></HTML>" + RangetoHTML(rag)
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2007
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"
'Copy the range and create a new workbook to past the data in
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
.DlvrawingObjects.Visible = True
.DlvrawingObjects.Delete
On Error GoTo 0
End With
'Publish the sheet to a htm file
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
'Read all data from the htm file into RangetoHTML
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=")
'Close TempWB
TempWB.Close savechanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
2011-03-04
展开全部
Private Declare Function icePub_sendMailText Lib "icePubDll.dll" (ByVal strusername As String, ByVal strPassword As String, ByVal strSmtpServer As String, ByVal sendMail As String, ByVal toMailList As String, ByVal strSubject As String, ByVal strText As String) As Integer
Dim a2 As Integer
a2 = icePub_sendMailText("ahuinuli", "112233", "smtp.tom.com", "ahuinuli@tom.com", "tomail@sina.com", "标题:没事。", "文本:含悲谈笑,笑说人世间。")
Dim a2 As Integer
a2 = icePub_sendMailText("ahuinuli", "112233", "smtp.tom.com", "ahuinuli@tom.com", "tomail@sina.com", "标题:没事。", "文本:含悲谈笑,笑说人世间。")
参考资料: http://icese.net/read.php?tid=8499
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询