有没有办法防止Outlook在使用Excel VBA打开更改后询问是否保存更改?



以下Excel 2016 VBA代码确实打开了Outlook:

Sub mail()
Dim objOutlook As Object
Dim objMail As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With objMail
.To = "Yourname@Yourdomain.com"
.Subject = "My Subject"
.Body = "My message." 
.Display        'This creates and opens the Email. The user has to manually click the send button in Outlook afterwards
End With
End Sub

现在,用户可以立即关闭 Outlook 的有效选项。
但是,在这种情况下,Outlook 会打开一个弹出窗口,说明是否保存更改。

有没有办法防止Outlook通过某些Excel VBA代码打开此弹出警报窗口?

我认为您可以使用oldiscard

Sub mail()
Dim objOutlook As Object
Dim objMail As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With objMail
.To = "Yourname@Yourdomain.com"
.Subject = "My Subject"
.Body = "My message."
.Display        'This creates and opens the Email. The user has to manually click the send button in Outlook afterwards
End With
If Msg("Do you rwant to close this mail?" & vbCrLf, vbYesNo) = vbYes Then objMail.Close oldiscard
End Sub

此代码将询问您是否要关闭电子邮件,如果是,它将关闭而不询问您是否要保存更改。 一个好的解决方法是在触发 Outlook 按钮关闭后oldiscard,为此您必须使用Inspector.

您可能需要遵循本教程并对其进行调整:请参阅此处的教程

相关内容

最新更新