Use VB.Net for Excel scripting - excel

I understand it is very well possible to write scripts in VB.Net which are able to create/manipulate Excel application and its object structure. Is there a workaround that would allow one to include or otherwise integrate the VB.Net code into a particular workbook so that a regular user could run it? E.g.:
Having the script in VB.Net in a separate file next to the Excel file and call it through VBA.
Inserting the VB.Net script file into the workbook (like one can insert any other file) and then running it by double-clicking it
The aim is to go around some of the limitations and archaisms of VBA as well as being able to use some more modern and user-friendly IDE (such as VSCode) instead of the built-in VBE.

Related

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

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?
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.

Dealing with excel files what can be used besides VBA?

I have been working on an excel file which will combine each of the excel files
sent by the users. So I will have a user entry row per file.
I started by using VBA. I thought that it would be the best, natural choice, though
I did not know how to use it previously. At the moment I have come across problems that I have no idea how to solve in VBA - I want to open each of the excel files that contains a user form seamlessly even if it contains VBA code, but what happens is that each opening user gets a dialog that requires them to accept or reject VBA.
I really like to learn new things but it is starting to annoy me. I do hope there some other solution to do that, but not in VBA. Is it possible to do that in some other language, and fire it from VBA?
I would love to have all bounded in that master excel file, or at most just to provide some library. The excel version is 2003.
how are you opening the file? Workbooks.Open will open an excel file which has vba without asking the user to accept or reject code.
Perhaps its an issue with the security settings you have. You can check these out from the menu - Tools, Macro and then security
your question is not well defined.
if you need to manipulate Excel files without opening Excel program, you can use other programming languages. Either interface with the COM / ActiveX objects that excel provides to the operating system, or use independent libraries (e.g. for PHP, Java, Python and more).
Another solution (to whatever problem you may have) is to use OpenOffice for working with excel files. It has its own macro language, as well as built-in bridges and interfaces to java & python.

Call Excel COM Addins functions using macro

How can I call a function defined in a COM Addin using excel macro ?
Basically I have created a Excel COM Addin which does some bunch of stuff.
Now I want to invoke this via excel macros.
Is it possible to do it ?
Or
Is it possible to install COM Addin using a macro ?
You can reference COM libraries in the VBA editor by going to tools -> references (I think) then you can select (or browse for) whatever DLL you've created. When you've selected it there you can use the functions contained within in the usual way.
You should see a big list of libraries to select from.
When I've done VBA development in the past I normally end up using a few things like the Microsoft XML libraries through this method.

Resources