Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting the following error message reported by Excel 2003.

Run-time error '-2147024894 (80070002)';

File or assembly name ZZZ, or one of its dependencies, was not found.

Here is the VBScript in Excel:
VB
Private Sub Workbook_Open()
  Dim mgr As Object
  Range("C2").Value = ""
  Range("C3").Value = ""
  Range("C4").Value = ""
  Range("C5").Value = ""
  Set mgr = CreateObject("ZZZ.X")
  If Not mgr Is Nothing Then
    Dim conn As String
    conn = mgr.GetConnectionStrWithRole("...")
    If Len(conn) > 0 Then
      Range("C2").Value = mgr...
      Range("C3").Value = mgr...
      Range("C4").Value = mgr...
      Range("C5").Value = conn
    End If
    Set mgr = Nothing
  End If
End Sub


If I put the following code in test.vbs it works:
VB
Sub Test()
  Set mgr = CreateObject("ZZZ.X")
  mgr.GetConnectionStrWithRole("...")
End Sub

call Test


If I put the following code in a 2.0 .Net Console App it works:
C++
Module Module1

  Sub Main()
    Dim u As Object
    Try
      u = CreateObject("ZZZ.X")
      Console.WriteLine("A......: {0}", u.....)
      Console.WriteLine("B......: {0}", u.....)
    Catch ex As Exception
      Console.WriteLine("EXCEPT.......: {0}", ex.Message)
    End Try
  End Sub

End Module


The ZZZ.X is a 2.0 .Net ServiceComponent

C++
X.cs as follows

namespace ZZZ
{
  [Transaction(TransactionOption.Required),ComVisible(true)]
  public sealed class X : System.EnterpriseServices.ServicedComponent
  {
    public X()
    {
    }
    // ... public methods and properties
  }
}

assembly.cs contains

...
[assembly: ComVisible(false)]
[assembly: ApplicationActivation(ActivationOption.Library)]
[assembly: ApplicationName("ZZZ")]
...


The registry contains the ZZZ.X and CLSID information. Anyone have any ideas why the Excel 2003 vbscript isn't able to create the COM object?
Posted

1 solution

Try this I compiled a windows form into a class file by switching the compiler option to produce a Dll, then assigned these attributes to the class, registers the class as a COM interop and finally, I referenced the dll in the VB script editor under tools reference. It seems to work. The implementation here is just code so ignore it.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Tungsten
{
	[System.Runtime.InteropServices.ComVisible(true)]
	[System.Runtime.InteropServices.Guid("ba16c8e9-125d-41d3-b4ad-214095778db4")]
	[System.Runtime.InteropServices.ProgId("Tungsten.Isotope")]
	public partial class Isotope : Form
	{
		public DateTime current;
		public string timeRep;
		public string GetDateTime()
		{
			timeRep = current.ToString();
			return current.ToString();
		}
		public string TheTime
		{
			get
			{
				timeRep = current.ToString();
				return GetDateTime();
			}
		}
		public Isotope()
		{
			InitializeComponent();
			this.Show();
		}

		private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
		{
			current = dateTimePicker1.Value;
		}
	}
}


/*  excel VB code HERE
Private Sub Workbook_Open()
Dim x As Tungsten.Isotope
Dim a As String

Set x = CreateObject("Tungsten.Isotope")

a = x.TheTime
a = x.GetDateTime()
a = x.timeRep


End Sub

*/
 
Share this answer
 
v2
Comments
Putz2008 9-Jun-10 11:53am    
The [assembly: ComVisible(false)] is according to Microsoft documentation, however, on the off chance that there was a problem with the documentation, I also tried this with [assembly: ComVisible(true)] and it fails as well.
icestatue 10-Jun-10 11:32am    
I have reposted a sample of code that worked for me if you are interested.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900