BA在EXCEL 和outlook 中编程实现自动发mail功能 不会弹出 Outlook 的安全提示框
在电脑中设定任务计划,定时打开存有代码的EXCEL,此程序可实现定时自动发MAIL功能,
可同时发给多人或群组,邮件可带附件,邮件内容来自EXCEL表格中,将要发送的excel 内容区域命名为 LIST,
无论什么版本的OUTLOOK都无需插件或设置都不会弹出以下窗口:
'以下代码贴于outlook的 ThisOutlookSession模块中(记得在outlook中引用EXCEL)
Option Explicit
Sub send_mail(w, zt, PAT, strHTMLBody As String)
Set mai = Application.CreateItem(0)
With mai
.To = w
.subject = zt
mai.FlagIcon = olRedFlagIcon
mai.FlagDueBy = Date
.Attachments.Add PAT
.HTMLBody = strHTMLBody
.Send
End With
Set mai = Nothing
End Sub
'以下代码贴于EXCEL的 thisworkbook模块中(记得在excel中引用OUTLOOK)
Option Explicit
private Sub Workbook_Open()
sendmail
End Sub
Sub sendmail()
Dim OutApp As Object
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Dim rag As Range
Dim note As String
Dim subject As String
Dim who As String
Dim Attachment As String
Dim strHTMLBody As String
Set rag = Range("list")
subject = "Rs Defect Chart"
note = "alarm:"
who = "" '邮件接受者,多个用户可使用冒号隔开
Attachment = "D:ATaw.XLS"
strHTMLBody = "
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