VBA VS. VSTO what is the difference, should I upgrade?

前端 未结 4 1064
太阳男子
太阳男子 2021-02-07 01:00

I am a huge fan of the KISS principle (Keep it simple) and a long time VBA for excel user. However all the articles I can find on VBA vs. VSTO (Visual Studio Tools for Office) s

相关标签:
4条回答
  • 2021-02-07 01:14

    VBA in Excel gives you the advantage of having fast results between editing your code and running your code. Because you are a good VBA programmer, you could live without the super feature from Visual Studio (intellisense, try-catch-fanally, inherits, every .NET objects, multi-threading ...)

    VSTO is a way to work inside a very good IDE (Visual Studio), but i am afraid you will waste a lot of time switching between VB.NET and your Excel. It is not as direct as your VBA inside your Excel.

    If your main purpose of programming is to stay inside your Excel file, then stay with VBA. If you really need to work outside your excel file or if you want to do something that doesn't necessary depend on your excel files, maybe you could consider VSTO. Beside, VSTO is pretty new and documentation may not be complete.

    I would stay with VBA if I were you. THIS IS MY HUMBLE OPINION. I wrote a little comparative between VBA and VB.NET (VSTO): Here's Difference between VB.NET and VBA!

    0 讨论(0)
  • 2021-02-07 01:16

    This is 6 years after this question was originally asked so it's possible that at the time of the OP a comparison between these two tools were different, but I am actually very surprised at how favorable the existing answers are towards VBA!

    VBA is interpreted and housed entirely within the application. The advantages here are:

    • Coding can be done directly within the application, requiring no external tools
    • Application-specific features like Macro recording can enable quick prototyping
    • You can leverage Excel-specific ActiveX controls like RefEdit
    • UDFs can be developed easily
    • AddIns are distributed as documents (.xla format)

    For small applications and UDFs VBA works fine. You can build quickly and easily in Excel and things "just work."

    If your program has any type of complexity however, it would be very worthwhile to explore VSTO. Advantages there include:

    • Ability to use multi-paradigm programming languages like VB.NET or C#
    • Better collection support (generic lists, dictionaries, tuples, etc...)
    • Support for threads, asynchronous execution
    • Deployment of AddIns as standalone applications
    • Ability to use native WinForms and develop non-blocking UIs

    VSTO is at this point is pretty well documented:

    https://docs.microsoft.com/en-us/visualstudio/vsto/create-vsto-add-ins-for-office-by-using-visual-studio

    The topic of performance is rather vague but to contrast some of the previous answers this really depends on your bottlenecks. COM interoperability may add overhead, but at the same time the VBA execution model is much slower than what can be offered by C#. Particularly when you take into account the various paradigms that programming a VSTO can offer three are applications where a VSTO will be orders of magnitude faster than a similarly coded VBA program.

    0 讨论(0)
  • 2021-02-07 01:33

    Which toolset you use is largely a matter of personal preference, but here are some things to consider:
    1. Performance: For most Excel-related tasks VSTO performs very slowly compared to VBA because of the additional Interop layer.
    2. UDFs: VSTO does not support UDFs
    3. Object Model: Its harder to work with the Excel object model with VSTO than with VBA because there is no .NET Macro recorder to give you hints.
    4. IDE: With VSTO you get access to the latest Visual Studio IDE (assuming you have a Visual Studio license)
    5. .Net Framework: VSTO gives you access to the very rich and powerful .NET framework
    6. Learning curve: VB.NET is a different language to VBA and the .NET framework and object model differences mean that the transition is not as simple as it could be.
    7. If you want to go the visual studio/.NET route I would recommend you look at Addin Express or XLDNA rather than VSTO: both of these have less limitations than VSTO

    0 讨论(0)
  • 2021-02-07 01:36

    I'm very surprised by your answers towards VBA.

    Working with VBA for some years (mainly with outlook), I was bored with various negative aspects and I'm moving to VSTO since it is much more efficient.

    I was confronted to many negative points:

    Developping

    • Vba IDE is very limited,
    • Userforms are limited (try to make a rich text box)

    Deploying

    • User need to do too many actions (modify security settings, import references, modify ribbon ...)

    Updating

    • Can't be updated automatically, you need to send new files for each update to the user .

    Add-ins are much more powerfull (by powerfull I mean it's easier to make complexe things), can add buttons to ribbons to lauch functions and are more easy to deploy (take a look at ClickOnce).

    Generally, VBA macros are made for a personnal use while VSTO applications are made to be distributed as you can read here:

    https://support.microsoft.com/en-us/help/290779/managing-and-distributing-outlook-visual-basic-for-vba

    If you are developing a solution that you intend to distribute to more than a few people, you should convert your VBA code into an Outlook COM or VSTO add-in or an Office add-in for Outlook.

    0 讨论(0)
提交回复
热议问题