Excel 2010的64位没办法创建.NET对象
问题说明
我有在Excel中使用一个简单的类库。这里是我的类的简化...
I have a simple class library that I use in Excel. Here is a simplification of my class...
using System;
using System.Runtime.InteropServices;
namespace SimpleLibrary
{
[ComVisible(true)]
public interface ISixGenerator
{
int Six();
}
public class SixGenerator : ISixGenerator
{
public int Six()
{
return 6;
}
}
}
在Excel 2007中我会创造宏启用工作簿,然后添加一个模块下面的代码:
In Excel 2007 I would create a macro enabled workbook and add a module with the following code:
Public Function GetSix()
Dim lib As SimpleLibrary.SixGenerator
lib = New SimpleLibrary.SixGenerator
Six = lib.Six
End Function
然后在Excel中,我可以调用函数GetSix(),它会返回六人。这不再是在Excel 2010工作64位。我得到一个运行时错误'429':ActiveX组件不能创建对象
Then in Excel I could call the function GetSix() and it would return six. This no longer works in Excel 2010 64bit. I get a Run-time error '429': ActiveX component can't create object.
我试图改变目标平台到x64,而不是任何CPU,但随后我的代码不会编译除非我取消选中了注册COM互操作选项,这样使得它让我的宏工作簿能不能看到SimpleLibrary.dll因为它不再regsitered。
I tried changing the platform target to x64 instead of Any CPU but then my code wouldn't compile unless I unchecked the Register for COM interop option, doing so makes it so my macro enable workbook cannot see SimpleLibrary.dll as it is no longer regsitered.
任何想法如何,我可以用我的图书馆与Excel 2010 64位?
Any ideas how I can use my library with Excel 2010 64 bit?
正确答案
您还没有详细说明如何创建你的.NET程序集。不过,也有揭露大会COM所需的步骤一定数量的:
You haven't described in detail how your created your .NET assembly. However, there are a certain number of steps required to expose the assembly to COM:
-
添加以下属性到您的代码:
-
Add the following attributes to your code:
using System;
using System.Runtime.InteropServices;
namespace SimpleLibrary
{
[ComVisible(true)]
[Guid("71F645D0-AA78-4447-BA26-3A2443FDA691")]
public interface ISixGenerator
{
int Six();
}
[ComVisible(true)]
[ProgId("SimpleLibrary.SixGenerator")]
[Guid("8D59E0F6-4AE3-4A6C-A4D9-DFE06EC5A514")]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class SixGenerator : ISixGenerator
{
[DispId(1)]
public int Six()
{
return 6;
}
}
}
-
您必须装配签署(项目 - >属性 - >签署的,形成强大的关键文件,并检查盒子签署组装
-
Your assembly must be signed (Project -> Properties... -> Signing, create a strong key file and check the box to sign the assembly
下面的命令是必要的注册程序集(全部在一行中):
The following command is necessary to register the assembly (all in one line):
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\RegAsm.exe SimpleLibrary.dll /tlb SimpleLibrary.tlb /codebase
这将创建一个.TLB类型库文件,你会从你的VBA项目引用(工具 - >引用 - >浏览... 的在VBA编辑器)
This creates a .tlb type library file which you will have to reference from your VBA project (Tools -> References -> Browse... in your VBA editor)
调整VBA代码:
Public Function GetSix() Dim lib As SimpleLibrary.SixGenerator Set lib = New SimpleLibrary.SixGenerator GetSix = lib.Six End Function
You will find the steps described in more detail in this article on Microsoft's support database:
的如何调用一个Visual Basic .NET或Visual Basic 2005组件从Visual Basic 6.0
How to call a Visual Basic .NET or Visual Basic 2005 assembly from Visual Basic 6.0
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfijfe
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20