TLDR:
I am writing and testing a script from VBA but it is ultimately executed as a single .bas
file from the main desktop application.
The DLL Reference is lost from VBA to the bas
forcing me to define the application's members types as "object" instead of their native type in the .bas
file.
Can I avoid converting early-bound to late-bound code by defining a reference in the bas file?
More info:
I need to convert vba scripts to a basic script which the software can execute. Is there anyway within the basic script to reference the tlb file? I call the application using set app = CreateObject("...")
The examples show everything typed as an "object" in their examples which gives no intellisense from VBA(of course)
Is it possible to reference the enums as their text value without converting them back to their integer value? Also, is there a way to properly type the application objects instead of using object
in a basic script?
Can I avoid converting early-bound to late-bound code by defining a reference in the bas file?
No, you can't. A .bas file doesn't contain such metadata. In fact the only metadata it holds, is the name of the module, stored as a hidden VB_Name
attribute that the VBE uses to populate the module's Name
property.
References belong to a VBProject
object; if you want a .bas file to stand on its own and be executable outside the VBE through VBScript runtime, then you must convert your early-bound code to late-bound.
This means you indeed lose intellisense, because all the types defined in that late-bound library must now be declared as Object
, and enum values need to be converted to their underlying integer values.
Alternatively you can define same-name constants for these enums, and keep the names:
Private Const SomeEnumValue As Long = 42
Or, [re]define the enums yourself:
Private Enum SoneEnum
SomeEnumValue = 42
'...
End Enum