Home » excel » excel – Can VBA Code Be Run Outside of MS Applications?

excel – Can VBA Code Be Run Outside of MS Applications?

Posted by: admin March 9, 2020 Leave a comment

Questions:

I just started to learn VBA. As far as I understood, one uses VBA to write macros in MS-Excel. But I wonder if it the only area of application for VBA. Can it be also used like many other standard languages – like Python, for example.

If it is the case, how can I compile a VBA program? Should it be compiled? How can I run such a VBA program?

How to&Answers:

VBA is compiled to p-code. P-code is an intermediate language that requires an additional runtime in order to execute. This runtime is hosted by most Microsoft Office applications (including various non-Microsoft applications).

In short, you cannot write a VBA only app that is compiled to an .EXE.

Answer:

To create a stand-alone VBA-like program, you would need to use Visual Basic 6 or earlier. The successor of Visual Basic 6, of course, is VB.NET, which is a very different animal.

Answer:

VBA can be licensed, and there are quite a few pproducts outside office that use VBA. MS no longer issues new licenses. There are non-MS VBA implementations, like from Summit software. In any case you need to have your own product that would host VBA.

Answer:

A notable application supporting VBA is AutoDesk AutoCAD. It licenses the VBA runtime and has it’s own object model.

Answer:

If you don’t compile the program ahead of time (in the Visual Basic Editor click Debug -> Compile), then Microsoft Office compiles it at run time. You really should compile frequently though because that is how you find compile errors.

How you run a VBA application depends entirely on how you have set it up to run. In Excel for example you can have the Workbook_Open event start your code when the workbook is opened or create custom menus that users click on to run the code. In Access, you can set a form to display when the database opens or create an autoexec macro that will run when the database opens. etc. etc.

Like someone else said above, you can’t create .exe files of VBA. The code has to run in a Microsoft Office Application.