2015-11-20 15 views
1

我想寫一個簡單的程序來自動發送來自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 

回答

1

這是你需要手動操作更多信息:

  1. 運行Outlook作爲管理員
  2. 進入工具(Outlook 2007中)或文件,選項(展望2010年及以上)
  3. 轉到信任中心
  4. 更改編程訪問設置爲:Never warn me about suspicious activity

現在,您可以關閉Outlook,從現在起,你將有機會每次都沒有彈出!


BTW,避免打開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 
+0

謝謝! 我沒有想過添加一個catch來檢查多個實例,所以生病一定要加入,謝謝! – user1787114