Roman
Roman

Reputation: 131278

Can VBA Code Be Run Outside of MS Applications?

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?

Upvotes: 8

Views: 31208

Answers (5)

Michiel van der Blonk
Michiel van der Blonk

Reputation: 720

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

Upvotes: 1

qwerty
qwerty

Reputation: 21

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.

Upvotes: 2

mischab1
mischab1

Reputation: 1601

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.

Upvotes: -2

phoog
phoog

Reputation: 43076

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.

Upvotes: 4

Justin Self
Justin Self

Reputation: 6265

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.

Upvotes: 7

Related Questions