Solved

Error 430: Class does not support Automation or does not support expected interface

Posted on 2006-06-30
3
405 Views
Last Modified: 2013-12-25
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.CommandBars
    End If
   
    Set oStandardBar = oCommandBars.Item("Standard")
    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.Count()              
        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!



0
Comment
Question by:sterlingdev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Accepted Solution

by:
hiteshgupta1 earned 500 total points
ID: 17029752
0
 
LVL 9

Expert Comment

by:lojk
ID: 17037675
are you sure that thte controls collection isnt zero based?

i.e.
For I =  To oStandardBar.Controls.Count()-1

and

 Set MyButton = oStandardBar.Controls.Add(0)    
0
 

Author Comment

by:sterlingdev
ID: 17041570
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.CommandBarEvents(myButton)

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
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question