我如何可以利用.NET对象从Excel VBA中?可以利用、对象、VBA、NET

2023-09-03 03:33:32 作者:萌够就回家

能否VBA code实例化和使用.NET对象?具体的类,我感兴趣的是System.IO.Com pression.GZipStream。

Can VBA code instantiate and use .NET objects? The specific class I'm interested in is System.IO.Compression.GZipStream.

对于信息 GAC是.NET全局程序集缓存

For Info GAC is the .NET Global Assembly Cache

推荐答案

我觉得安迪钉这个答案,但我不能确定有关CLR加载规则方面是完全正确的。

I think Andy nailed this answer, but I'm not certain that the aspect regarding the CLR loading rules is exactly right.

.NET程序集持有该类充当包装GZipStream将面临COM和注册的,就像任何其他COM项目库和类。在这方面,VBA会发现在COM暴露.NET组件经由注册表中的位置。这可能是聪明的把大会在GAC,使其不能移动(因为移动大会将无效的注册表信息),但只要注册表指向正确的地方,应该没事。

The .NET Assembly that holds the class acting as the wrapper for GZipStream would be exposed to COM and registered just like any other COM project library and class. In this regard, VBA would find the location of the COM-exposed .NET assembly via the registry. It might be smart to put the assembly in the GAC, so that it can't move (since moving the assembly would invalidate the registry info), but so long as the registry points to the right place, it should be fine.

关于这个问题的一个很好的初级教程这里

A good beginner's tutorial on the subject is here

希望这有助于...