我正在尝试编写一个简单的程序来自动从excel中的列表发送电子邮件,并且它可以正常工作,但Outlook会不断打开要求权限的弹出窗口。你如何获得不再要求许可的前景,只是在没有弹出窗口的情况下做excel告诉它的事情
这是我到目前为止的代码:
Sub SendMessage()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim recemail
Dim i As Integer
i = 1
recemail = Sheet1.Cells(i, 1)
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(recemail)
objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.Subject = "TEST!"
.Body = "DOES THIS WORK!?"
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
i = i + 1
End Sub
答案 0 :(得分:1)
这是您需要执行的手动操作:
Never warn me about suspicious activity
您现在可以关闭Outlook,从现在开始,您每次都可以访问而无需弹出窗口!
顺便说一句,为了避免打开一个新的Outlook实例(如果已经有),请使用:
'Create or Get the Outlook session.
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err.Number > 0 Then Set objOutlook = CreateObject("Outlook.Application")
On Error GoTo 0