How to fully qualified names from VBA project to object?

203 views Asked by At

If I have many macro workbooks open at the same time...

Some names such as UserForm, Module, etc. overlap. How to fully qualified names from VBA project?

for example:

VBAProject(ThisWorkbook.Name).UserForm1.CommandButton1.Caption
MyNameOfProject(ThisWorkbook.Name).UserForm1.CommandButton1.Caption

When the user renames the workbook, the project name remains the same... Ideally completely avoid the workbook name, if posible?

In one workbook, for example, there is a module with a function that I would like to use from the other workbook. In general, I want things to be under control. Fully qualified as much as possible.

1

There are 1 answers

0
Kin Siang On

When you are referring to userform within the same work, you can just use:

From:

MyNameOfProject(ThisWorkbook.Name).UserForm1.CommandButton1.Caption

To:

UserForm1.CommandButton1.Caption

However, for referring userform from another workbook, please avoid to do so...