Using CancelDefault with a CommandBarButton

D

DataDay

Hello,

I'm using "Dim WithEvents btnEmail As CommandBarButton" to drop the click
event of the Mail Recipient (with attachment) in Word. I can catch the event
and fire other actions, but the default action will not cancel. Any
suggestions?

Thanks

Private Sub btnEmail_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)

CancelDefault = True
'Do something else instead

End sub
 
P

Perry

You can intercept the Email button on the "Standard" commandbar by placing
your code in ThisDocument class module
You will have to redirect the button using some other code like in below
example:
'macro in a standard module
Sub ReDirectEmailBtn()
Set ThisDocument.btnEmail = CommandBars(1).Controls(5)
End Sub

'these lines in classmodule: ThisDocument
Public WithEvents btnEmail As Office.CommandBarButton
Private Sub btnEmail_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
CancelDefault = True
'Go ahead and do other stuff
End Sub

Krgrds,
Perry
 
P

Perry

Disabling the button on the "standard" commandbar will also disable the File
| Sent To email recipient ...
Have you tried it ??
 
P

Perry

Sub ReDirectEmailBtn(Optional ByVal Restore As Boolean)
If Restore Then
'<<restore functionality
Set ThisDocument.btnEmail = Nothing
Else
'<<this is the one on the standard toolbar
rem Set ThisDocument.btnEmail = CommandBars("Menu Bar").Controls(5)

'<<this is the File | Sent To (as attachment)
Set ThisDocument.btnEmail = _
CommandBars("Menu Bar").Controls(1).Controls(18).Controls(4)

End If
End Sub
 
D

DataDay

Yes, I did try you method, but it does not give me the results I need.

The email button on the standard toolbar and File|Send To|Mail Recipient
(with attachment) function in two different ways. I do not wish to disable
the button on the standard toolbar. I need to "highjack" the click event of
File|Send To|Mail Recipient (with attachment) supress the action it normally
takes and have it call my own function (not one that corisponds to an
existing button).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top