PDA

View Full Version : CommandBarComboBox Event



qazpl
02-10-2007, 08:26 PM
I am using Microsoft Office 2003 and I am developing an Add-in for Microsoft Word written in Visual Basic 6 (I know I am behind the times!!). In the process I am having a difficult time with CommandBarComboBox Event. So that you can recreate my Issue I have made a sample Add-in Project and attached it to this issue. If you don't want to download then create an empty vb6 add-in project, add references to Microsoft Office & Word, remove dialog and change application in Connect Dialog to Microsoft Word.

This is my Code:



Option Explicit

'Implement extensibility library.
Implements IDTExtensibility2

Public WithEvents myWordApp As Word.Application
Public myCommandBar As Office.CommandBar
Public WithEvents myCommandBarButton As Office.CommandBarButton
Public WithEvents myDropdown As Office.CommandBarComboBox
Public myInstance As Object

Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)

End Sub

'------------------------------------------------------
' Runs when add-in loads in Office application
' Can run when user loads add-in from Office COM Add-Ins dialog box,
' on startup, or when another application loads add-in.
'------------------------------------------------------
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)

Set myWordApp = Application
Set myInstance = AddInInst
End Sub

'-----------------------------------------------------------
' Runs when add-in is unloaded from Office application.
' Can run when user manually unloads add-in from Office
' COM Add-Ins dialog box, when application shuts down, or
' when another application unloads the add-in.
'-----------------------------------------------------------
Private Sub IDTExtensibility2_OnDisconnection(ByVal _
RemoveMode As AddInDesignerObjects.ext_DisconnectMode, _
custom() As Variant)

Set myWordApp = Nothing
Set myInstance = Nothing

End Sub

Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
'Debug.Print "OnStartupComplete"
End Sub

Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
'Debug.Print "OnAddInsUpdate"
End Sub

Private Sub myCommandBarButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox "CommandButton Works"
End Sub

Private Sub myDropdown_Change(ByVal Ctrl As Office.CommandBarComboBox)
MsgBox "Dropdown Works"
End Sub

Private Sub myWordApp_WindowBeforeRightClick(ByVal Sel As Word.Selection, Cancel As Boolean)
Cancel = True
Set myCommandBar = CommandBars.Add(Name:="MainMenuBar", Position:=msoBarPopup, temporary:=True)

'add commandbutton
Set myCommandBarButton = myCommandBar.Controls.Add(temporary:=True)
With myCommandBarButton
.Caption = "CommandButton Test"
.OnAction = "!<myInstance.ProgId>"
End With

'add dropdown
Set myDropdown = myCommandBar.Controls.Add(Type:=msoControlDropdown, _
temporary:=True)

With myDropdown
.Width = 1
.Caption = "Dropdown Test"
.AddItem ("One")
.AddItem ("Two")
.AddItem ("Three")
.OnAction = "!<myInstance.ProgId>"
End With

myCommandBar.ShowPopup
End Sub


The Issue is that I can't get the Combobox Change Event to work. Every time I click it I get an error Message that my Macro Cannot be found like this.

http://vbaexpress.com/forum/C:\Documents and Settings\user 01\My Documents\Portable.VB6\sub_files\i

My Macro Security is at lowest setting)


While The Command Button works perfectly, the combobox fails every time. For my Project I don't need that it should use the Change Event, it would suffice if the "OnAction" property would be able to reference sub in my Add-in. However I could only get "OnAction" to reference sub in my Macros but not in my Add-in giving me the same error message. If on your computer this add-in works then please let me know which version of Microsoft Office you are using. Thanks In Advance.

qazpl
02-10-2007, 08:43 PM
here is the error image.