What causes a Visual Basic -2147319765 (8002802b) runtime error in Excel when an ActiveX control was installed?

I created an ActiveX control using C ++. I am using Visual Basic code for an instance of a control in an Excel worksheet. I can only run VB script once, subsequent runs result in the following runtime error when trying to access the ActiveSheet variable:

Microsoft Visual Basic Run-time error '-2147319765 (8002802b)': Automation error Element not found 

I am trying to figure out what causes this error, and how can I fix it?

As an experiment, I tried to create a simple ActiveX control created by Visual Studio wizards (both in VS 2005 and 2008). I did not add or modify any code in this case. A simple test case still causes this error.

Other ActiveX controls on the system do not cause this error (for example, I tried to configure a "bitmap") from VB code.

This is the VB code (the macro I wrote, but the VB with manual encoding has the same problem):

 Sub Macro1() ActiveSheet.OLEObjects.Add(ClassType:="test.test_control.1" _ , Link:=False, DisplayAsIcon:=False).Select End Sub 

Can someone give me an answer to this? Alternatively, any resource pointers that may help can be appreciated.

thanks

+4
source share
5 answers

After talking with Microsoft, I found out the cause of the problem that I encountered.

When creating an ActiveX control using the VS 2005/2008 wizard, you need to select the "Connection points" checkbox on the "Settings" page. This adds, among other things, IConnectionPointContainerImpl as the base class for your ATL class, which in turn implements IConnectionPointContainer.

Failure to do this means that you cannot insert an ActiveX control into an Excel document through Visual Basic more than once. The second time you run the script, you start to receive "automation errors".

The answer to the problem was quite simple, and it worked, although I still don’t know how this is related to the “automation error”, and leaves me wondering why the error messages are not more informative.

+2
source

You have created an "unskilled" link to an Excel application that cannot be freed using a global variable designed for VBA that should not be used in VB 6.0.

This is an unfortunate side effect of using VB 6.0, but it is the only problem that I know about using VB6, and it is easy to fix.

The problem in your case is related to the use of the global variable ActiveSheet. When using VBA, this is fine, but when using VB 6.0, you should avoid this or create an Excel application that you cannot free up. This approach will work fine the first time, but will cause all kinds of undefined behavior to appear the second time when your procedure starts.

In your example, the code should do something like this:

 Sub Macro1() Dim xlApp As Excel.Application Set xlApp = New Excel.Application xlApp.ActiveSheet.OLEObjects.Add(ClassType:="test.test_control.1" _ , Link:=False, DisplayAsIcon:=False).Select ' Then when done: xlApp.Quit() xlApp = Nothing End Sub 

For a detailed discussion of how to deal with this in general, see

VB 6.0 Tutorial - Finding and eliminating unqualified links ( http://www.xtremevbtalk.com/showthread.php?p=900556#post900556 )

For Microsoft documentation on this issue, see:

Excel Automation does not work in the second temporary code (MSKB 178510) ( http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q178/5 /10.asp )

Error or unexpected behavior when automating Office when using early binding in Visual Basic (MSKB 319832) ( http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q319832& )

Change Please note that the use of html 'a' tags for some reason did not work with these links. Someone may need to look into the parser?

+3
source

I got another message, but the behavior was weird like this problem. Take a look at my question here . In my case, VBA CodeCleaner did the trick.

0
source

From the description of the error and guessing the bits, I suggest you try the following.

  • Make sure you cannot create ActiveX controls elsewhere without problems. This might just be an ActiveX creation issue, not an Excel issue.

Also in relation now you need to use the generic "test.test_control", not "test.test_control.1", but that is not your problem.

0
source

I had this error with UserControl classes that executed interfaces manually, but without events. In this case, the solution was to declare an empty interface for the ComSourceInterfaces attribute:

 [ComVisible( true )] [Guid( "your-guid-here" )] [ProgId( "progid-here" )] [ComDefaultInterface( typeof( IMyClass ) )] [ComSourceInterfaces( typeof( IMyClassEvents ) )] [ClassInterface( ClassInterfaceType.None )] public partial class ExcelMap : UserControl, IMyClass { //implementation here } [ComVisible( true )] [Guid( "your-2nd-guid" )] [InterfaceType( ComInterfaceType.InterfaceIsDual )] public interface IMyClass { //whatever things you need to define here } [ComVisible( true )] [Guid( "your-3rd-guid" )] [InterfaceType( ComInterfaceType.InterfaceIsDual )] public interface IMyClassEvents { //empty interface to avoid Automation errors //you can define events here in the normal way, but it not necessary } 
0
source

All Articles