sterlingdev
asked on
Error 430: Class does not support Automation or does not support expected interface
Hi,
I have a VB6 Add-In. I've written code to create a menu item on the "Add-Ins" menu and a CommandBar button on the "Standard" toolbar (both coded in the OnStartupComplete event for certain reasons).
The menu item works perfectly so no problem on that front...
However, when I try to add a new Control on the Standard toolbar the program falls over with the error message from the title.
Here's the code I'm using for this purpose:
Dim WithEvents MyButton As CommandBarButton (declared at class-level in the Connect class)
Set oCommandBars = VBInstance.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer object
Set oCommandBars = VBInstance.ActiveExplorer. CommandBar s
End If
Set oStandardBar = oCommandBars.Item("Standar d")
If oStandardBar Is Nothing Then
' Standard bar not found: use the 'Text Editor' toolbar
Set oStandardBar = oCommandBars.Item("Text Editor")
End If
' Ensure that the 'Standard' toolbar is enabled & visible
oStandardBar.Enabled = True
oStandardBar.Visible = True
' In case the button was not deleted, use the exiting one...
'Set MyButton = oStandardBar.Controls.Item ("MyAddIn" )
For I = 1 To oStandardBar.Controls.Coun t()
If oStandardBar.Controls.Item (I).Tag() = "MyAddIn Button" Then
' My button's tag was found and hence my button already exists...
' Set my button variable to it
Set MyButton = oStandardBar.Controls.Item (I)
Exit For
End If
Next
'... otherwise, create a new button
If MyButton Is Nothing Then
Set MyButton = oStandardBar.Controls.Add( 1) --> this is the statement which generates the error I've mentioned!!!!!!!!!
...
End If
Other information...
I'm using:
VB6 (SP5)
Office 2003 (v.11)
Windows XP Pro
The 3 references added automatically by the Add-In project when I created it are:
Microsoft Office 11.0 Object Library
Microsoft Add-In Designer
Microsoft Visual Basic 6.0 Extensibility
Has anyone come across this problem? What's the workaround?
Thanks!
I have a VB6 Add-In. I've written code to create a menu item on the "Add-Ins" menu and a CommandBar button on the "Standard" toolbar (both coded in the OnStartupComplete event for certain reasons).
The menu item works perfectly so no problem on that front...
However, when I try to add a new Control on the Standard toolbar the program falls over with the error message from the title.
Here's the code I'm using for this purpose:
Dim WithEvents MyButton As CommandBarButton (declared at class-level in the Connect class)
Set oCommandBars = VBInstance.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer object
Set oCommandBars = VBInstance.ActiveExplorer.
End If
Set oStandardBar = oCommandBars.Item("Standar
If oStandardBar Is Nothing Then
' Standard bar not found: use the 'Text Editor' toolbar
Set oStandardBar = oCommandBars.Item("Text Editor")
End If
' Ensure that the 'Standard' toolbar is enabled & visible
oStandardBar.Enabled = True
oStandardBar.Visible = True
' In case the button was not deleted, use the exiting one...
'Set MyButton = oStandardBar.Controls.Item
For I = 1 To oStandardBar.Controls.Coun
If oStandardBar.Controls.Item
' My button's tag was found and hence my button already exists...
' Set my button variable to it
Set MyButton = oStandardBar.Controls.Item
Exit For
End If
Next
'... otherwise, create a new button
If MyButton Is Nothing Then
Set MyButton = oStandardBar.Controls.Add(
...
End If
Other information...
I'm using:
VB6 (SP5)
Office 2003 (v.11)
Windows XP Pro
The 3 references added automatically by the Add-In project when I created it are:
Microsoft Office 11.0 Object Library
Microsoft Add-In Designer
Microsoft Visual Basic 6.0 Extensibility
Has anyone come across this problem? What's the workaround?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to all!
However, I'm giving the points to hiteshgupta1 as the article mentioned is interesting and could prove useful in the future...
However, the workaround which solved my problem is as folows:
I replaced the module-level declaration of my button...
Dim WithEvents myButton As Office.CommandBarButton
with...
Dim myButton As Office.CommandBarButton
Dim WithEvents MenuHandler2 As CommandBarEvents
Then, at the bottom of the event where I wanted to create the commandbar button I added the following code:
Set MenuHandler2 = VBInstance.Events.CommandB arEvents(m yButton)
Obviously the event fired when the user clicks my button will be:
Private Sub MenuHandler2_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
...
End Sub
However, I'm giving the points to hiteshgupta1 as the article mentioned is interesting and could prove useful in the future...
However, the workaround which solved my problem is as folows:
I replaced the module-level declaration of my button...
Dim WithEvents myButton As Office.CommandBarButton
with...
Dim myButton As Office.CommandBarButton
Dim WithEvents MenuHandler2 As CommandBarEvents
Then, at the bottom of the event where I wanted to create the commandbar button I added the following code:
Set MenuHandler2 = VBInstance.Events.CommandB
Obviously the event fired when the user clicks my button will be:
Private Sub MenuHandler2_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
...
End Sub
i.e.
For I = To oStandardBar.Controls.Coun
and
Set MyButton = oStandardBar.Controls.Add(