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

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?

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.

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.

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.

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

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.

Related

Call Office 365 new-style add-in from VBA

I'm maintaining a legacy Excel workbook that has a significant amount done in VBA. For threading's sake, I need to move some of that work out of VBA. I have prototyped a DLL written in C#, but deployment (with registration) is more difficult.
Can you interact with the new HTML5 style add-ins using VBA? So, in this case, writing a function in Javascript, and then calling it with specific parameters from the existing VBA macro. If so, how?
Unfortunately this is not a scenarios supported by Microsoft nowadays.

Distributing an Excel add-in (.xlam) whose code cannot be viewed by the user

I am fairly experienced with Excel and VBA and I know how to create add-ins. However, I haven't found a satisfactory solution for protecting my VBA code once it is in an add-in. How can I make this code inaccessible to the user?
You can protect your VBA code against viewing, however it is relatively easy to crack.
You can easily Google out how to protect a VBA module.
Alternatively, you can create an Add in using Visual Studio. Yet again, .Net code can be decompiled in seconds. Thus, you would need to use a code obfuscator.

Can VBE be invoked/used OUTSIDE of an Office Application?

This may be a silly question - I haven't found anything on Google about this. No new programs populate in the task manager when VBE is opened from an Office Application, and I don't see an executable that looks probable. DLL maybe?
Some Office applications provide the Run method for the Application class. For example, see Run Excel Macro from Outside Excel Using VBScript From Command Line.
Yes, you can call VBA macro at runtime.
There are applications that don't provide any specific methods for that, for example, Outlook. In that case you can use the late-binding technology (see Type.InvokeMemeber) - see Calling Outlook VBA Macro from outside (VB/VBScript/C#).
You can invoke a CommandBarButton's OnAction macro as a proxy for Application.Run.
For details, see this question How can I run a macro from a VBE add-in, without Application.Run?

how many ways to do programming in Excel . except for VBA

I want to manipulate data in excel with some complex functions.
It seems that I have to use VBA.
However I don't want to learn it.
Is there any other way to do programming in the excel? Some language like C#?
I don't want to create a independent C# application using some interface provided by Excel. Only program in excel, like VBA, but a different language.
I don't want to create a independent C# application using some interface provided by Excel. Only program in excel, like VBA, but a different language.
You cannot unfortunately. To program in Excel from within Excel you will have to learn VBA.
To program for Excel, be it VBA, VSTO(C#, VB.Net) you need to understand the Excel Object Model (EOM) without which you cannot do programming for Excel.
You don't need to learn VBA per se if you want to develop Office solutions from C# but as you become familiar with the EOM, you will notice that you automatically develop an understanding for VBA.
EDIT
Excel Object Model from Excel's perspective
Excel Object Model Overview from VS's perspective
You can develop Excel "Add-Ins" in C# using VSTO - Visual Studio Tools for Office (MSDN link).
This is not truly "inside Excel," but once installed your add-in can run without having to start up any external application.
Excel has a VBA editor built in to use VBA only.
If you want to use another language it would need to be external.
While you could make a C# add in, this is not in the built in editor as you described.
To the best of my knowledge, you simply cannot do this right now. In Office 15 it looks as though you'll be able to use JS:
http://www.zdnet.com/blog/microsoft/microsoft-to-focus-on-html5-and-javascript-for-office-15-extensions/10266

Writing excel file to vb6

i have an excel file template and i want save the written value in textboxes to the cells of excel using vb6 language.
can anyone help me?
You can do this using Excel's automation features from any language that supports COM (directly or indirectly); here's an example using VB.Net. There are also examples using VB6 out there still, but see my comment on your question, creating new applications with VB6 is a potential problem as the dev environment (compiler, for instance) is no longer supported (the runtime still is, for a little while yet, to support apps that already exist). The dev environment still works (under XP, at least) to my (sad) knowledge, but expect it to start having trouble as OS's move on...

Resources