在Excel 2002中可以访问的Visual Studio 2005中创建DLL [英] Create DLL in Visual Studio 2005 accessible by Excel 2002

查看:117
本文介绍了在Excel 2002中可以访问的Visual Studio 2005中创建DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Studio 2005-Visual Basic中创建一个包含

自定义函数的DLL。我相信我需要使用COM互操作来允许VBA代码在
Excel 2002中访问它。我已经研究了我在COM Interop上可以找到的所有东西

和.NET。我还尝试了MSDN网站上的许多''演练'

与COM加载项,.NET和Office XP有关但我甚至无法获得这些'/ $
在Excel 2002或Word 2002中工作。


我已经安装了Office XP PIA';我安装了Office XP SP3;我是在Windows XP Pro SP2系统上开发的



特别是文章,如何使用构建Office COM加载项 Visual

Basic .NET"位于 http://support.microsoft.com/kb/302896/,在Excel 2002中没有
函数。它在Access 2002和PowerPoint 2002中有效,但是
但是我相信加载项正在正确注册GAC。


当我启动Excel时,我没有收到连接消息,也没有按钮但是excel

启动时没有错误。关闭Excel时,我没有收到断开连接消息,

。 Word中的行为是相同的。此外,Word或Excel

启动后,

" HKEY_CURRENT_USER \Software \ Microoft \ Office \ [OfficeApp] \Addins \ [ProgID ] \ LooBehavior"

注册表项从0x03更改为0x02。在Access中这不会发生。


我甚至不关心命令栏按钮用于我的目的;我只想要

才能访问我的自定义功能。


有什么建议吗?


PS一些我研究的参考资料是:


信息:使用Visual Studio .NET开发Microsoft Office解决方案
http://support.microsoft.com/kb/311452/EN-US/


Office XP主互操作程序集已知问题
http://msdn.microsoft.com/library/de..._piaissues.asp


演练:使用Visual Basic 2005创建COM对象
http: //msdn2.microsoft.com/en-us/library/x66s8zcd.aspx

.NET Framework应用程序中的COM互操作性
http://msdn2.microsoft.com/en-us/library/e7a79b4y.aspx


以及其他许多人......

I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains
custom functions. I believe I need to use COM interop to allow VBA code in
Excel 2002 to access it. I''ve studied everything I can find on COM Interop
and .NET. I''ve also tried many of the ''Walkthroughs'' on the MSDN site
relating to COM add-ins, .NET and Office XP but am unable to get even these
working in Excel 2002 or Word 2002.

I''ve installed the Office XP PIA''s; I have Office XP SP3 installed; I''m
developing on a Windows XP Pro SP2 system.

Specifically the article, "How To Build an Office COM Add-in by Using Visual
Basic .NET" located at http://support.microsoft.com/kb/302896/, doesn''t
function in Excel 2002. It does work in Access 2002 and PowerPoint 2002,
however so I believe the Add-in is being correctly registered in the GAC.

When I start Excel, I get no ''connect'' message and no button but excel
starts without error. I get no ''disconnect'' message on closing Excel,
either. The behavior is the same in Word. Also, After the Word or Excel
starts, the
"HKEY_CURRENT_USER\Software\Microsoft\Office\[OfficeApp]\Addins\[ProgID]\LoadBehavior"
registry entry changes from a 0x03 to a 0x02. This doesn''t happen in Access.

I don''t even care about the commandbar buttons for my purposes; I just want
to have access to my custom functions.

Any suggestions?

PS Some of the references I''ve researched are:

INFO: Develop Microsoft Office solutions with Visual Studio .NET
http://support.microsoft.com/kb/311452/EN-US/

Office XP Primary Interop Assemblies Known Issues
http://msdn.microsoft.com/library/de..._piaissues.asp

Walkthrough: Creating COM Objects with Visual Basic 2005
http://msdn2.microsoft.com/en-us/library/x66s8zcd.aspx

COM Interoperability in .NET Framework Applications
http://msdn2.microsoft.com/en-us/library/e7a79b4y.aspx

And many others...

推荐答案

你对此进行的研究比我有,但让我们从

开始基础知识。


您是否可以使用添加<添加对COM对象的引用br />
参考" Excel / Visual Basic编辑器的工具菜单中的对话框?


adm


Steve写道:
You have done more research into this than I have, but let''s start with
the basics.

Are you able to add a reference to your COM object using the "Add
Reference" dialog in the Excel/Visual Basic editor''s Tools menu?

adm

Steve wrote:

我试图在Visual Studio 2005-Visual Basic中创建一个包含

自定义函数的DLL。我相信我需要使用COM互操作来允许VBA代码在
Excel 2002中访问它。我已经研究了我在COM Interop上可以找到的所有东西

和.NET。我还尝试了MSDN网站上的许多''演练'

与COM加载项,.NET和Office XP有关但我甚至无法获得这些'/ $
在Excel 2002或Word 2002中工作。


我已经安装了Office XP PIA';我安装了Office XP SP3;我是在Windows XP Pro SP2系统上开发的



特别是文章,如何使用构建Office COM加载项 Visual

Basic .NET"位于 http://support.microsoft.com/kb/302896/,在Excel 2002中没有
函数。它在Access 2002和PowerPoint 2002中有效,但是
但是我相信加载项正在正确注册GAC。


当我启动Excel时,我没有收到连接消息,也没有按钮但是excel

启动时没有错误。关闭Excel时,我没有收到断开连接消息,

。 Word中的行为是相同的。此外,Word或Excel

启动后,

" HKEY_CURRENT_USER \Software \ Microoft \ Office \ [OfficeApp] \Addins \ [ProgID ] \ LooBehavior"

注册表项从0x03更改为0x02。在Access中这不会发生。


我甚至不关心命令栏按钮用于我的目的;我只想要

才能访问我的自定义功能。


有什么建议吗?


PS一些我研究的参考资料是:


信息:使用Visual Studio .NET开发Microsoft Office解决方案
http://support.microsoft.com/kb/311452/EN-US/


Office XP主互操作程序集已知问题
http://msdn.microsoft.com/library/de..._piaissues.asp


演练:使用Visual Basic 2005创建COM对象
http: //msdn2.microsoft.com/en-us/library/x66s8zcd.aspx

.NET Framework应用程序中的COM互操作性
http://msdn2.microsoft.com/en-us/library/e7a79b4y.aspx


以及其他许多人...
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains
custom functions. I believe I need to use COM interop to allow VBA code in
Excel 2002 to access it. I''ve studied everything I can find on COM Interop
and .NET. I''ve also tried many of the ''Walkthroughs'' on the MSDN site
relating to COM add-ins, .NET and Office XP but am unable to get even these
working in Excel 2002 or Word 2002.

I''ve installed the Office XP PIA''s; I have Office XP SP3 installed; I''m
developing on a Windows XP Pro SP2 system.

Specifically the article, "How To Build an Office COM Add-in by Using Visual
Basic .NET" located at http://support.microsoft.com/kb/302896/, doesn''t
function in Excel 2002. It does work in Access 2002 and PowerPoint 2002,
however so I believe the Add-in is being correctly registered in the GAC.

When I start Excel, I get no ''connect'' message and no button but excel
starts without error. I get no ''disconnect'' message on closing Excel,
either. The behavior is the same in Word. Also, After the Word or Excel
starts, the
"HKEY_CURRENT_USER\Software\Microsoft\Office\[OfficeApp]\Addins\[ProgID]\LoadBehavior"
registry entry changes from a 0x03 to a 0x02. This doesn''t happen in Access.

I don''t even care about the commandbar buttons for my purposes; I just want
to have access to my custom functions.

Any suggestions?

PS Some of the references I''ve researched are:

INFO: Develop Microsoft Office solutions with Visual Studio .NET
http://support.microsoft.com/kb/311452/EN-US/

Office XP Primary Interop Assemblies Known Issues
http://msdn.microsoft.com/library/de..._piaissues.asp

Walkthrough: Creating COM Objects with Visual Basic 2005
http://msdn2.microsoft.com/en-us/library/x66s8zcd.aspx

COM Interoperability in .NET Framework Applications
http://msdn2.microsoft.com/en-us/library/e7a79b4y.aspx

And many others...





好​​的。超级简单,这里是一个完整的C#COM可见类库


使用System;

使用System.Collections.Generic;

使用System.Text;

使用System.Runtime.InteropServices;

使用System.Reflection;


[assembly: ComVisible(true)]

[assembly:Guid(" 37496b5c-462a-4547-b57e-d9063256e443")]

[assembly:AssemblyVersion(" 1.0.0.0) ")]

[assembly:AssemblyFileVersion(" 1.0.0.0")]


命名空间ExcelFunctions

{


[ClassInterface(ClassInterfaceType.AutoDual)]

公共类函数

{

public double添加(双a,双b)

{

返回+ b;

}

}

}


在VS2005中创建一个DLL项目,粘贴此代码,签名,构建它,GAC它

然后注册它COM与regasm.exe互操作。

然后从Excel宏设置对库的引用(这给你

intellisense)并使用它:

Private Sub Worksheet_SelectionChange(ByVal Target as Range)


Dim f作为ExcelFunctions.Functions

设置f = CreateObject(" ExcelFunctions.Functions")

MsgBox f.Add(1,2)


End Sub

同样的VBScript也可以用来测试.vbs文件中的COM库。


David


CreateObject(" MyComponent.MyClass)

" Steve" < St *** @ discuss.microsoft.com写信息

新闻:CE ************************* ********* @ microsof t.com ...


Ok. Super simplistically, here''s a complete C# COM-visible class library

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;

[assembly: ComVisible(true)]
[assembly: Guid("37496b5c-462a-4547-b57e-d9063256e443")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

namespace ExcelFunctions
{

[ClassInterface(ClassInterfaceType.AutoDual)]
public class Functions
{
public double Add(double a, double b)
{
return a + b;
}
}
}

Create a DLL project in VS2005, paste this code, sign it,build it, GAC it
and then register it for COM interop with regasm.exe.
Then from an Excel macro set a reference to the library (this gives you
intellisense) and use it:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim f As ExcelFunctions.Functions
Set f = CreateObject("ExcelFunctions.Functions")

MsgBox f.Add(1, 2)

End Sub
This same VBScript can be used to test the COM library from a .vbs file too.

David

CreateObject("MyComponent.MyClass)
"Steve" <St***@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...

>我正在尝试在Visual Studio 2005-Visual Basic中创建一个DLL
包含

自定义函数。我相信我需要使用COM互操作来允许VBA代码


Excel 2002中访问它。我已经研究了我在COM上可以找到的所有内容。

Interop

和.NET。我还尝试过MSDN网站上的许多''演练'

与COM加载项,.NET和Office XP相关但我甚至无法获得

这些

在Excel 2002或Word 2002中工作。


我已经安装了Office XP PIA';我安装了Office XP SP3;我是在Windows XP Pro SP2系统上开发的



特别是文章,如何使用构建Office COM加载项

Visual

Basic .NET"位于 http://support.microsoft.com/kb/302896/,在Excel 2002中没有
函数。它在Access 2002和PowerPoint 2002中有效,但是
但是我相信加载项正在正确注册GAC。


当我启动Excel时,我没有收到连接消息,也没有按钮但是excel

启动时没有错误。关闭Excel时,我没有收到断开连接消息,

。 Word中的行为是相同的。此外,Word或Excel

启动后,

" HKEY_CURRENT_USER \Software \ Microoft \ Office \ [OfficeApp] \Addins \ [ProgID ] \ LooBehavior"

注册表项从0x03更改为0x02。这不会发生在

访问。


我甚至不关心命令栏按钮用于我的目的;我只需要

想要

就可以访问我的自定义功能。


有什么建议吗?


PS我研究的一些参考资料是:


信息:使用Visual Studio .NET开发Microsoft Office解决方案
http://support.microsoft.com/kb/311452/EN-US/


Office XP主互操作程序集已知问题
http://msdn.microsoft.com/library/de..._piaissues.asp


演练:使用Visual Basic 2005创建COM对象
http://msdn2.microsoft.com/en-us/library/x66s8zcd.aspx

.NET Framework应用程序中的COM互操作性
http://msdn2.microsoft.com/en-us/library/e7a79b4y.aspx


还有很多其他......
>I am trying to create a DLL in Visual Studio 2005-Visual Basic that
contains
custom functions. I believe I need to use COM interop to allow VBA code
in
Excel 2002 to access it. I''ve studied everything I can find on COM
Interop
and .NET. I''ve also tried many of the ''Walkthroughs'' on the MSDN site
relating to COM add-ins, .NET and Office XP but am unable to get even
these
working in Excel 2002 or Word 2002.

I''ve installed the Office XP PIA''s; I have Office XP SP3 installed; I''m
developing on a Windows XP Pro SP2 system.

Specifically the article, "How To Build an Office COM Add-in by Using
Visual
Basic .NET" located at http://support.microsoft.com/kb/302896/, doesn''t
function in Excel 2002. It does work in Access 2002 and PowerPoint 2002,
however so I believe the Add-in is being correctly registered in the GAC.

When I start Excel, I get no ''connect'' message and no button but excel
starts without error. I get no ''disconnect'' message on closing Excel,
either. The behavior is the same in Word. Also, After the Word or Excel
starts, the
"HKEY_CURRENT_USER\Software\Microsoft\Office\[OfficeApp]\Addins\[ProgID]\LoadBehavior"
registry entry changes from a 0x03 to a 0x02. This doesn''t happen in
Access.

I don''t even care about the commandbar buttons for my purposes; I just
want
to have access to my custom functions.

Any suggestions?

PS Some of the references I''ve researched are:

INFO: Develop Microsoft Office solutions with Visual Studio .NET
http://support.microsoft.com/kb/311452/EN-US/

Office XP Primary Interop Assemblies Known Issues
http://msdn.microsoft.com/library/de..._piaissues.asp

Walkthrough: Creating COM Objects with Visual Basic 2005
http://msdn2.microsoft.com/en-us/library/x66s8zcd.aspx

COM Interoperability in .NET Framework Applications
http://msdn2.microsoft.com/en-us/library/e7a79b4y.aspx

And many others...



是的,我可以添加参考它。如果我这样做,那么定义一个新的对象,如:


Dim o As MyAdAddin.Connect


VBA编辑器识别对象和'' intellisenses''班级。但是,公共子系统中没有一个是可见的。


" ad ***** @ yahoo.com"写道:
Yes, I can add a reference to it. If I do that then define a new object like:

Dim o As MyCOMAddin.Connect

The VBA Editor recognizes the object and ''intellisenses'' the class. None of
the Public Subs are visible, though.

"ad*****@yahoo.com" wrote:

你对此做了比我更多的研究,但让我们从

的基础开始。


您是否可以使用添加

参考添加对COM对象的引用Excel / Visual Basic编辑器的工具菜单中的对话框?


adm


Steve写道:
You have done more research into this than I have, but let''s start with
the basics.

Are you able to add a reference to your COM object using the "Add
Reference" dialog in the Excel/Visual Basic editor''s Tools menu?

adm

Steve wrote:

我试图在Visual Studio 2005-Visual Basic中创建一个包含

自定义函数的DLL。我相信我需要使用COM互操作来允许VBA代码在
Excel 2002中访问它。我已经研究了我在COM Interop上可以找到的所有东西

和.NET。我还尝试了MSDN网站上的许多''演练'

与COM加载项,.NET和Office XP有关但我甚至无法获得这些'/ $
在Excel 2002或Word 2002中工作。


我已经安装了Office XP PIA';我安装了Office XP SP3;我是在Windows XP Pro SP2系统上开发的



特别是文章,如何使用构建Office COM加载项 Visual

Basic .NET"位于 http://support.microsoft.com/kb/302896/,在Excel 2002中没有
函数。它在Access 2002和PowerPoint 2002中有效,但是
但是我相信加载项正在正确注册GAC。


当我启动Excel时,我没有收到连接消息,也没有按钮但是excel

启动时没有错误。关闭Excel时,我没有收到断开连接消息,

。 Word中的行为是相同的。此外,Word或Excel

启动后,

" HKEY_CURRENT_USER \Software \ Microoft \ Office \ [OfficeApp] \Addins \ [ProgID ] \ LooBehavior"

注册表项从0x03更改为0x02。在Access中这不会发生。


我甚至不关心命令栏按钮用于我的目的;我只想要

才能访问我的自定义功能。


有什么建议吗?


PS一些我研究的参考资料是:


信息:使用Visual Studio .NET开发Microsoft Office解决方案
http://support.microsoft.com/kb/311452/EN-US/


Office XP主互操作程序集已知问题
http://msdn.microsoft.com/library/de..._piaissues.asp


演练:使用Visual Basic 2005创建COM对象
http: //msdn2.microsoft.com/en-us/library/x66s8zcd.aspx

.NET Framework应用程序中的COM互操作性
http://msdn2.microsoft.com/en-us/library/e7a79b4y.aspx


和其他许多人......
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains
custom functions. I believe I need to use COM interop to allow VBA code in
Excel 2002 to access it. I''ve studied everything I can find on COM Interop
and .NET. I''ve also tried many of the ''Walkthroughs'' on the MSDN site
relating to COM add-ins, .NET and Office XP but am unable to get even these
working in Excel 2002 or Word 2002.

I''ve installed the Office XP PIA''s; I have Office XP SP3 installed; I''m
developing on a Windows XP Pro SP2 system.

Specifically the article, "How To Build an Office COM Add-in by Using Visual
Basic .NET" located at http://support.microsoft.com/kb/302896/, doesn''t
function in Excel 2002. It does work in Access 2002 and PowerPoint 2002,
however so I believe the Add-in is being correctly registered in the GAC.

When I start Excel, I get no ''connect'' message and no button but excel
starts without error. I get no ''disconnect'' message on closing Excel,
either. The behavior is the same in Word. Also, After the Word or Excel
starts, the
"HKEY_CURRENT_USER\Software\Microsoft\Office\[OfficeApp]\Addins\[ProgID]\LoadBehavior"
registry entry changes from a 0x03 to a 0x02. This doesn''t happen in Access.

I don''t even care about the commandbar buttons for my purposes; I just want
to have access to my custom functions.

Any suggestions?

PS Some of the references I''ve researched are:

INFO: Develop Microsoft Office solutions with Visual Studio .NET
http://support.microsoft.com/kb/311452/EN-US/

Office XP Primary Interop Assemblies Known Issues
http://msdn.microsoft.com/library/de..._piaissues.asp

Walkthrough: Creating COM Objects with Visual Basic 2005
http://msdn2.microsoft.com/en-us/library/x66s8zcd.aspx

COM Interoperability in .NET Framework Applications
http://msdn2.microsoft.com/en-us/library/e7a79b4y.aspx

And many others...



这篇关于在Excel 2002中可以访问的Visual Studio 2005中创建DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆