我已经完成了一个自动提醒,可以从Excel发送电子邮件,由VBS文件(放在StartUp文件夹中)触发。当我打开我的电脑时,会触发提醒,它应该发送电子邮件,但我有一个安全错误。
这是Excel宏:
Sub Email()
Dim aOutlook As Object
Dim aEmail As Object
Dim i As Integer
For i = 1 To 100
If Cells(i, 3).Value = Date And IsEmpty(Cells(i, 7)) Then
Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)
aEmail.Importance = 2
aEmail.Subject = ActiveSheet.Cells(i, 4)
aEmail.Body = ActiveSheet.Cells(i, 5)
aEmail.To = ActiveSheet.Cells(i, 6)
aEmail.Send
Cells(i, 7).Value = "Sent: " & Now
End If
Next i
End Sub
这是VBS文件:
Dim xlApp, xlBook
Set wshShell = CreateObject( "WScript.Shell" )
Set xlApp = CreateObject("Excel.Application")
userName = wshShell.ExpandEnvironmentStrings( "%UserName%" )
Set xlBook = xlApp.Workbooks.Open("C:\Users\" + userName + "\Desktop\RM.xlsm", 0, False)
xlApp.Application.Run "Email"
xlBook.Save
xlBook.Close
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
如何通过在我的宏中添加更多内容来绕过此错误?
(我已经尝试了谷歌的所有代码,但它们都不起作用。我也不想在Outlook设置或Windows Reg上进行任何更改。)
答案 0 :(得分:1)
您有几个选择:
有关讨论和可用选项列表,请参阅http://www.outlookcode.com/article.aspx?id=52。
答案 1 :(得分:0)