
Click event does not fire for CommandBarButton if the button does not fit on a docked toolbar
I have a
Visual Basic 6.0 application that creates a toolbar in
Microsoft Word 2000. The toolbar contains several controls,
including a CommandBarButton. I want to respond to the
CommandBarButton's Click event within my VB code. I declare
a CommandBarButton within my VB code (withevents) and capture
the Click event for that object. This works fine unless the
toolbar is docked and the button does not fit on the toolbar.
In this case the button can be accessed through the
[>>(More Buttons)] button on the end of the toolbar, but when
the button is clicked in this manner, the Click event does not
fire in my VB application. Is this a bug or am I missing something?
(I am using VB 6.0 SP5 and Office2000 SP2.)
Below is sample code that will duplicate this behavior. When Word opens,
resize the window until button 4 is no longer visible.
Private myWordApp As Word.Application
Private WithEvents myButton As Office.CommandBarButton
Private Sub Form_Load()
Set myWordApp = New Word.Application
myWordApp.Documents.Add
With myWordApp.ActiveDocument.CommandBars.Add("Test", msoBarTop, , True)
.Visible = True
End With
With myWordApp.ActiveDocument.CommandBars("Test")
With .Controls.Add(msoControlButton)
.Caption = "This is test button number 1"
.BeginGroup = True
.Style = msoButtonCaption
End With
With .Controls.Add(msoControlButton)
.Caption = "This is test button number 2"
.BeginGroup = True
.Style = msoButtonCaption
End With
With .Controls.Add(msoControlButton)
.Caption = "This is test button number 3"
.BeginGroup = True
.Style = msoButtonCaption
End With
Set myButton = .Controls.Add(msoControlButton)
With myButton
.Caption = "This is test button number 4"
.BeginGroup = True
.Style = msoButtonCaption
End With
End With
myWordApp.Visible = True
End Sub
Private Sub myButton_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
Debug.Print "Click Event Fired"
End Sub
Thanks in advance,
Tad Smith, MCSD