给予优秀的前景控制

我试图编写一个简单的程序来自动发送来自Excel中的列表的电子邮件,它的工作原理,但Outlook不断打开popup窗口要求权限。 你如何得到前景不再要求许可,只要做好excel告诉它没有popup窗口

下面是我到目前为止的代码:

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 

这是您需要执行的手动操作:

  1. 以pipe理员身份运行Outlook
  2. 转到工具(Outlook 2007)或文件,选项(Outlook 2010及更高版本)
  3. 去信任中心
  4. 将“程序化访问”设置更改为: Never warn me about suspicious activity

您现在可以closuresOutlook,从现在开始,每次没有popup窗口就可以访问!


顺便说一句,为了避免打开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