2017-09-26 40 views
2

目前,我有一組編碼被設置爲自動發送以前用戶輸入生成的電子郵件。使用Excel VBA以編程方式禁止Outlook電子郵件發送警告消息

當它被調用時,它私下生成/發送一封電子郵件 - 但要求用戶接受「好」,「取消」或「幫助」。

如果用戶退出窗格或單擊取消,則不發送電子郵件。

有沒有辦法讓程序自動選擇命令好嗎?

Private Sub sendemail() 

Dim outlookapp As Object 
Dim mitem As Object 
Dim cell As Range 
Dim email_ As String 
Dim subject_ As String 
Dim body_ As String 
Dim attach_ As String 

'''>>>EMAIL<<<''' 
Set outlookapp = CreateObject("Outlook.Application") 


email_ = "[email protected]" 
subject_ = "General Subject" 
body_ = "General Message" 

'create Mail Item and send it 
Set mitem = outlookapp.CreateItem(0) 
With mitem 
    .To = email_ 
    .Subject = subject_ 
    .Body = body_ 
    '.Attachments.Add "C:\FolderName\Filename.txt" 
    '.Display 'To Display the message with an option to send or cancel 

    .Send 'To auto-send the message 
End With 

End Sub 

我用下面的代碼試過,但覺得我可以用它在錯誤的地方,因爲它是不成功的:

Application.DisplayAlerts = False 

'With function/code 

Application.DisplayAlerts = True 
+2

在Security選項卡下的Outlook選項中,您會發現「其他應用程序嘗試發送郵件時發出警告」旁邊的複選框。只需取消選中此複選框。 – sktneer

+0

使用此係統的用戶大約有100人,這是每個用戶都需要做的事情嗎?還是有什麼我可以添加到它的代碼,只是自動選擇「好」選項? – Excelatwhat

回答

0

你可以試試這樣的事情...

Set mitem = outlookapp.CreateItem(0) 
With mitem 
    .To = email_ 
    .Subject = subject_ 
    .Body = body_ 
    '.Attachments.Add "C:\FolderName\Filename.txt" 
    .Display 'To Display the message with an option to send or cancel 
    Application.Wait (Now + TimeValue("0:00:02")) 
    Application.SendKeys "%s" 
End With 
相關問題