How do I get events from a "Split Button Popup" control?

T

Tim Sylvester

I want to execute some VBA addin (or possibly C# COM addin) code any
time that a user pastes data into an office document. To accomplish
this, I've added event handlers to the cut, copy and paste commands in
Excel. This is done by finding the commands (21, 19 and 22) in the
CommandBars collection by command ID and setting up "_Click" handlers
for each command. The default "Standard" toolbar contains a paste
control (ID 6002) that is a CommandBarPopup instead of a
CommandBarButton. Unfortunately, this popup type does not source any
events. I can successfully sink events from the items on the popup
menu from this popup button, but not from the button itself. How can
I get notification that this button has been clicked?

Any information would be greatly appreciated, I've tried everything I
can think of on this one. Please CC any responses to me via e-mail at
<[email protected]>.

Thanks!

===== Begin VBA Addin (.xla) Source =====

' This allows us to get events from the "standard" paste commands
Private WithEvents PasteButton As Office.CommandBarButton

' Attempting declare a CommandBarPopup with events fails:
' "Object does not source automation events"
'Private WithEvents PastePopup As Office.CommandBarPopup


Private Sub Workbook_Open()
' Find the "standard" paste button to begin sinking events
Set PasteButton =
Application.CommandBars.FindControl(Type:=msoControlButton, ID:=22)

' Find the "split button popup" type paste command
Dim PastePopup As CommandBarPopup
Set PastePopup =
Application.CommandBars.FindControl(Type:=msoControlSplitButtonPopup,
ID:=6002)

if (Not PastePopup Is Nothing) then
' Events can be trapped from buttons on the popup's
' embedded command bar...
'Set Paste1 = PastePopup.Controls.Item(1)

' Attempting to set an OnAction handler for this control
' results in an error:
' "Object doesn't support this property or method"
'PastePopup.OnAction = "ThisWorkbook.TaskTracerPaste"

' Attempting to assign the "split button popup" control
' to a CommandBarButton object that can source events
' results in an invalid cast error.
end if
End Sub

===== End VBA Addin (.xla) Source =====
 

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