0
votes

I want to run integrated VBA functions like VBA.RGB() with the Application.Run() command. This method is stored in C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA7.1\VBE7.DLL

According to this Microsoft article, running methods stored in a DLL should be feasible with Application.run: https://docs.microsoft.com/en-us/office/vba/api/Excel.Application.Run

But how exactly may I do this? None of the code lines below are working.

Sub RunFunction()
    Dim ExampleValue As Variant
    ExampleValue = Application.Run("RGB", 1, 1, 1)
    ExampleValue = Application.Run("C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA7.1\VBE7.DLL!RGB", 1, 1, 1)
    ExampleValue = Application.Run("VBE7.DLL!RGB", 1, 1, 1)
    ExampleValue = Application.Run("VBE7!RGB", 1, 1, 1)
End Sub

I would like to avoid wrapping all these standard functions into some module functions.


Edit - To further specify my question:

At the end of the day I would like to create a CallByName-like function that is capable to run integrated VBA functions from a function name given as a string. CallByName requires an object to invoke methods or properties. Example: CallByName Workbooks, "Add", VbMethod You may not invoke VBA methods this way. CallByName VBA, "RGB", VbMethod, 1, 1, 1 would not work.

1
Do you want saying that method "RGB" does exist in a .dll? Did you create a reference to that specific .dll? - FaneDuru
Well when having a look in the object catalogue you will see that the VBA library is stored in the path mentioned above. The RGB function is part of this library. I'm not sure if I need to reference that DLL in a special way since it's the default DLL that will ALWAYS get referenced when creating a new VBA project. - GuidoT
You must have a reference to the .dll in discussion (which must have public methods), then you must declare a variable to point the dll: Dim x As New Your_Dll. And then use ExampleValue = x.RGB. Supposing that such a method, returning something exists in that specific dll. - FaneDuru
This .dll is Visual Basic for Applications, indeed... - FaneDuru
Trying to declare a variable like Dim V as VBA does not work since "VBA" is not an actual data type. But maybe I got you wrong there? How may I declare a variable as a DLL otherwise? I could use private declare function ... lib ... to add every single function from that DLL but thats pointless since these functions are available by default anyway. Furthermore I could wrap all these functions into self written module functions but thats something I would like to avoid. - GuidoT

1 Answers

0
votes

So, the .dll in discussion being VBA, you simply can use:

Dim testC As Color
   testC = RGB(1, 1, 1)