how to check details before sending mails in outlook using macros? [closed]

二次信任 提交于 2019-12-13 10:13:43

问题


I have to send mails to many different groups and sometimes I send to the wrong group.

I want to create VBA code to check, the initial two letters of subject header and also whether the same two initial letters are present in the mail body, as I send the mail. If the escalation is correct then mail should be sent otherwise the code should display some error message.


回答1:


It looks like you need to handle the ItemSend event of the Application class which is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program. Be aware, the Cancel parameter passed to the event handler allows to cancel the action. If the event procedure sets this argument to true, the send action is not completed and the inspector is left open.

Public WithEvents myOlApp As Outlook.Application  
Public Sub Initialize_handler()    
   Set myOlApp = Outlook.Application  
End Sub 

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)  
  Dim prompt As String  
  prompt = "Are you sure you want to send " & Item.Subject & "?"  
  If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then  
    Cancel = True  
  End If  
End Sub

In the code you can check out whatever you need - the Subject, Body or HTMLBody values.



来源:https://stackoverflow.com/questions/29260744/how-to-check-details-before-sending-mails-in-outlook-using-macros

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!