2003中的VBScript中的CreateObject失败

2003中的VBScript中的CreateObject失败

本文介绍了Excel 2003中的VBScript中的CreateObject失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到Excel 2003报告的以下错误消息.

运行时错误''-2147024894(80070002)'';

找不到文件或程序集名称ZZZ或其依赖项之一.

这是Excel中的VBScript:

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:

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



如果我将以下代码放在test.vbs中,它将起作用:



If I put the following code in test.vbs it works:

Sub Test()
  Set mgr = CreateObject("ZZZ.X")
  mgr.GetConnectionStrWithRole("...")
End Sub

call Test



如果我将以下代码放入2.0 .Net控制台应用程序中,它将起作用:



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

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



ZZZ.X是2.0 .Net ServiceComponent



The ZZZ.X is a 2.0 .Net ServiceComponent

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")]
...



注册表包含ZZZ.X和CLSID信息.任何人都知道为什么Excel 2003 vbscript无法创建COM对象?



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?

推荐答案

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

*/


这篇关于Excel 2003中的VBScript中的CreateObject失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 18:21