VBA equivalent to C# using or VB.NET imports / creating aliases

alias, c#, using-directives, vb.net, vba

Solution

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`'s (Programmatic Identifiers)

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` and `LateBinding`

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

This article explain where the names come from in Early Binding Section use the same link for When to use late binding

for MSDN Programmatic Identifiers section please see this

Problem

Base Reference: Ten Code Conversions for VBA, Visual Basic .NET, and C# Note: I have already created and imported a `*.dll`, this question is about aliases. Let's say the programmatic name of a `Test` class is `TestNameSpace.Test` ``` [ProgId("TestNamespace.Test")] public class Test ... ``` 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. This is in `VBA` : Instead of declaring a variable like this: ``` Dim myTest As TestNameSpace.Test Set myTest = new TestNameSpace.Test ``` I'd prefer to call it (still in VBE) ``` Dim myTest As Test Set myText = new Test ``` In C# you would normally say ``` using newNameForTest = TestNamespace.Test; newNameForTest myTest = new NewNameForTest; ``` Note: Assume there are no namespace conflicts in the `VBA` project Question: is there an equivalent call in `VBA` to `C#` `using` or `VB.NET` `imports` aliases?

Original source