VBA Macro - customize Reply Button

一世执手 提交于 2019-12-11 20:11:44

问题


I've written a macro to add BCC address on reply window. But I want to do the same on click of 'Reply' Button. I can not add macro to this button as it is not custom button. How should I do this?


回答1:


You can repurpose built-in controls. But in that case you need to develop an add-in, not a VBA macro. See Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.

Also you may try 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. In the event handler you may try to add a new entry to the Recipients collection (see the corresponding property) with the 'Type' property set to olBcc.




回答2:


This is from superuser.

https://superuser.com/questions/327614/outlook-macro-to-interrupt-a-reply-all

"You can add an event handler via VBA to pick up the ReplyAll event. Something like the following:"

Dim WithEvents insp As Outlook.Inspectors
Dim WithEvents mailItem As Outlook.MailItem

' This is called on Outlook startup
Private Sub Application_Startup()
    Set insp = Application.Inspectors
End Sub

' This is called when a new Inspector is created.
' You use it to pick up on a new mail item event
Private Sub insp_NewInspector(ByVal Inspector As Inspector)

    ' Edit:  The size test appears to be incorrect
    'If Inspector.CurrentItem.Size = 0 And Inspector.CurrentItem.Class = olMail Then

    If Inspector.CurrentItem.Class = olMail Then
       Set mailItem = Inspector.CurrentItem
    End If
End Sub

' Called when you press ReplyAll
Private Sub mailItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
    Dim msg As String
    Dim result As Integer
    msg = "Do you really want to reply to all?"
    result = MsgBox(msg, vbYesNo, "Reply All Check")
    If result = vbNo Then
        Cancel = True
    End If
End Sub

Put the code in the ThisOutlookSession module then restart.



来源:https://stackoverflow.com/questions/33278814/vba-macro-customize-reply-button

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