VBA等效于使用C#或VB.NET导入/创建别名 [英] VBA equivalent to C# using or VB.NET imports / creating aliases

查看:233
本文介绍了VBA等效于使用C#或VB.NET导入/创建别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本参考:针对VBA,Visual Basic的十代码转换.NET和C#

Base Reference: Ten Code Conversions for VBA, Visual Basic .NET, and C#

注意:我已经创建并导入了 *。dll ,这个问题是关于 别名

Note: I have already created and imported a *.dll, this question is about aliases.

让我们说一下程序名称 Test 类的一个是 TestNameSpace.Test

Let's say the programmatic name of a Test class is TestNameSpace.Test

[ProgId("TestNamespace.Test")]
public class Test ...

现在,说一个C#解决方案已经密封并编译成 *。dll ,我正在Excel的VBE中引用它。注意:目前,我无法修改程序名称,就好像 *。dll 不是我写的一样。

Now, say a C# solution has been sealed and compiled into a *.dll and I'm referencing it in a Excel's VBE. Note: at this point I cannot modify the programmatic name as if the *.dll wasn't written by me.

这是在 VBA 中:而不是像这样声明变量:

This is in VBA : Instead of declaring a variable like this:

Dim myTest As TestNameSpace.Test
Set myTest = new TestNameSpace.Test

我更喜欢称呼它(仍在VBE中)

I'd prefer to call it (still in VBE)

Dim myTest As Test
Set myText = new Test

C#您通常会说

using newNameForTest = TestNamespace.Test;
newNameForTest myTest = new NewNameForTest;

注意:假设<$ c $中没有名称空间冲突 c> VBA 项目

Note: Assume there are no namespace conflicts in the VBA project

问题: VBA 使用 VB.NET C# c $ c> 导入 别名?

Question: is there an equivalent call in VBA to C# using or VB.NET imports aliases?

推荐答案

答案是否定的:有一个内置的VBE功能,可以识别添加到项目中的引用,并在运行时(VBE的运行时)创建别名(如果没有名称冲突)

The answer is no: there is a built-in VBE feature that recognizes the references added to a project and creates aliases at run-time(VBE's runtime) if there are no name collisions

如果注册表中的名称冲突,所有点将替换为 _ 下划线。

In case of name conflicts in your registry all . dots will be replaces with _ underscores.

» ProgId 的  (程序标识符)

» ProgId's   (Programmatic Identifiers)

在COM中,仅用于后期绑定。这就是您如何调用以创建新对象

In COM, it is only used in late-binding. It's how you make a call to create a new object

Dim myObj = CreateObject("TestNamespace.Test")



» EarlyBinding LateBinding

在早期绑定中,您指定使用 new 关键字创建的对象的类型。您的对象名称应随VBA的智能提示一起弹出。它与 ProgId 没有关系。要检索用于对象类型的实际名称空间,请打开 Object Explorer F2 并将其定位在其中

In early binding you specify the type of object you are creating by using the new keyword. The name of you object should pop up with the VBA's intellisense. It has nothing to do with the ProgId. To retrieve the actual namespace used for your object type - open Object Explorer F2 and locate it there

本文早期绑定部分

中使用相同的链接用于何时使用后期绑定

MSDN程序标识符部分,请参阅这个

for MSDN Programmatic Identifiers section please see this

这篇关于VBA等效于使用C#或VB.NET导入/创建别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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