Question : How can I trigger a macro when the "send to mail" function is used?

Hi Experts,

Is there a way I can trigger a macro if the user uses the "Send To Mail as attachment" function in Excel?  I have a macro that runs a check and I would like this to be executed before the user sends the file as an attachment.  (If possible with a cancel boolean I can use to abort if necessary).

Thanks in advance

Joe.

(I am using excel 2003, but 2007 would be okay if 2003 cannot support.)

Answer : How can I trigger a macro when the "send to mail" function is used?

In the workbook's  ThisWorkbook module, use the code below. Adjust the Click event as needed.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Option Explicit
Private WithEvents btn As CommandBarButton

Private Sub btn_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
    ' test your condition to cancel the send
    If MsgBox("Do you wish to send?", vbYesNo) = vbNo Then
        CancelDefault = True
    End If
End Sub

Private Sub Workbook_Open()
    Set btn = Application.CommandBars.FindControl(ID:=2188)
End Sub
Random Solutions  
 
programming4us programming4us