223

What is the difference between the two. I always thought VBA is somewhat 'crippled' version of VB, but when a friend asked me the other day I had no idea what the actual differences are.

Also, when you use, for example, Excel, is that VB or VBA ?

0

9 Answers 9

188

For nearly all programming purposes, VBA and VB 6.0 are the same thing.

VBA cannot compile your program into an executable binary. You'll always need the host (a Word file and MS Word, for example) to contain and execute your project. You'll also not be able to create COM DLLs with VBA.

Apart from that, there is a difference in the IDE - the VB 6.0 IDE is more powerful in comparison. On the other hand, you have tight integration of the host application in VBA. Application-global objects (like "ActiveDocument") and events are available without declaration, so application-specific programming is straight-forward.

Still, nothing keeps you from firing up Word, loading the VBA IDE and solving a problem that has no relation to Word whatsoever. I'm not sure if there is anything that VB 6.0 can do (technically), and VBA cannot. I'm looking for a comparison sheet on the MSDN though.

10
  • 8
    There seems to be no concise comparison page on the microsoft.com pages, or they hid them well. Suffice it to say that VB 6.0 code runs unaltered in VBA, unless you make references to COM objects that are not shipped with VBA, of course.
    – Tomalak
    Commented Jun 14, 2009 at 18:54
  • 7
    VBA and Vb6 use the same dll file, which is why the code runs in either. However, there is something like a Printer object in VB6 that's not in VBA and I don't know why that is. Otherwise, I believe there are no differences in the base languages. Commented Jun 14, 2009 at 21:39
  • 51
    Which is why I think it's worth adding that opening an Office Document carries nearly the same risk as opening an executable.
    – Oorang
    Commented Jun 15, 2009 at 4:05
  • 15
    VB also has the Clipboard, Screen, and App objects, in addition to the Printers collection. The forms packages are completely different, as you have to go out of your way to avoid windowed controls in VB, but in VBA it's a lot harder to use hWnd-oriented API calls because most of the controls are windowless. And, speaking of controls, you can author your own in VB and use them in VBA as well as elsewhere. Lots of other niggles - see the Object Browser (press F2 in the IDE). Commented Jun 16, 2009 at 0:56
  • 7
    Note that this is outdated. VBA has been updated to VBA 7, with support for 64-bits data types (LongLong, LongPtr) and more changes. VB is stuck at version 6, so it doesn't support these new features. This answer discusses more changes. In short, there are now things VB can't do, but VBA can.
    – Erik A
    Commented Jul 4, 2018 at 20:22
51

VBA stands for Visual Basic for Applications and so is the small "for applications" scripting brother of VB. VBA is indeed available in Excel, but also in the other office applications.

With VB, one can create a stand-alone windows application, which is not possible with VBA.

It is possible for developers however to "embed" VBA in their own applications, as a scripting language to automate those applications.

Edit: From the VBA FAQ:

Q. What is Visual Basic for Applications?

A. Microsoft Visual Basic for Applications (VBA) is an embeddable programming environment designed to enable developers to build custom solutions using the full power of Microsoft Visual Basic. Developers using applications that host VBA can automate and extend the application functionality, shortening the development cycle of custom business solutions.

Note that VB.NET is even another language, which only shares syntax with VB.

9
  • 9
    Actually, Microsoft refers to VB.Net as "Visual Basic". See msdn.microsoft.com/en-us/vbasic/default.aspx.
    – DOK
    Commented Jun 14, 2009 at 18:22
  • 21
    Yes. That's a fact that makes me want to pull my hair out every time I look for VB or VBA-specific help via Google. Stupid marketing decision.
    – Tomalak
    Commented Jun 14, 2009 at 18:26
  • 8
    @Tomalak: That's why I just Noted that ;-)
    – fretje
    Commented Jun 14, 2009 at 18:36
  • 3
    @DOK: Yes indeed, but that doesn't change the fact that VB.NET is another language than the visual basic that "we developers" know as VB6 or earlier.
    – fretje
    Commented Jun 14, 2009 at 18:38
  • 4
    @j_random_hacker In this case, it almost feels like MS treats VB.Net a variant of VB, at least based on the visual studio vb page - which would not be accurate. Oddly enough, this wiki article provides more information on its face than the MS visual studio page :) en.wikipedia.org/wiki/Visual_Basic_.NET. However, a MSDN forum question looks to at least touch on the differences: social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/… Commented Jul 27, 2012 at 15:51
46

Here's a more technical and thorough answer to an old question: Visual Basic for Applications (VBA) and Visual Basic (pre-.NET) are not just similar languages, they are the same language. Specifically:

  • They have the same specification: The implementation-independent description of what the language contains and what it means. You can read it here: [MS-VBAL]: VBA Language Specification
  • They have the same platform: They both compile to Microsoft P-Code, which is in turn executed by the exact same virtual machine, which is implemented in the dll msvbvm[x.0].dll.

In an old VB reference book I came across last year, the author (Paul Lomax) even asserted that 'VBA' has always been the name of the language itself, whether used in stand-alone applications or in embedded contexts (such as MS Office):

"Before we go any further, let's just clarify on fundamental point. Visual Basic for Applications (VBA) is the language used to program in Visual Basic (VB). VB itself is a development environment; the language element of that environment is VBA."

The minor differences

Hosted vs. stand-alone: In practical, terms, when most people say "VBA" they specifically mean "VBA when used in MS Office", and they say "VB6" to mean "VBA used in the last version of the standalone VBA compiler (i.e. Visual Studio 6)". The IDE and compiler bundled with MS Office is almost identical to Visual Studio 6, with the limitation that it does not allow compilation to stand-alone dll or exe files. This in turns means that classes defined in embedded VBA projects are not accessible from non-embedded COM consumers, because they cannot be registered.

Continued development: Microsoft stopped producing a stand-alone VBA compiler with Visual Studio 6, as they switched to the .NET runtime as the platform of choice. However, the MS Office team continues to maintain VBA, and even released a new version (VBA7) with a new VM (now just called VBA7.dll) starting with MS Office 2010. The only major difference is that VBA7 has both a 32- and 64-bit version and has a few enhancements to handle the differences between the two, specifically with regards to external API invocations.

3
  • 2
    I recall that very same quote in Lomax's book, but given all the other statements to the contrary on this forum, on Wikipedia, etc., it makes me wonder who is right, and why there is disagreement! Lomax also wrote (p. 3), "VBA is the same language whether you are using it to create a VB application or to automate some task in Word or Excel." Also, "VBA is a hosted language and part of the VB family of development tools."
    – EJ Mak
    Commented Dec 11, 2016 at 19:24
  • 1
    If you choose help in VB6 you go to the VBA language reference. VB6, like Word, hosts the VBA language. As Application objects are global objects (Automation standard). VB6 provides a App object suitable for standalone programs. Word provides an App object for Word macros. Note the language is identical, any reference to things missing are to host provided objects like the VB6 printer object - it's not part of the language but of the host.
    – ACatInLove
    Commented Feb 7, 2018 at 2:11
  • When I was using VB6 and VBA, VBA loaded the VBA runtime library ~unless the VB6 runtime library was already in memory~. If the VB6 library was already in memory, VBA linked to that.
    – david
    Commented May 10, 2022 at 6:05
15

Do you want compare VBA with VB-Classic (VB6..) or VB.NET?

VBA (Visual Basic for Applications) is a vb-classic-based script language embedded in Microsoft Office applications. I think it's language features are similar to those of VB5 (it just lacks some few builtin functions), but:

You have access to the office document you wrote the VBA-script for and so you can e.g.

  • Write macros (=automated routines for little recurring tasks in your office-work)
  • Define new functions for excel-cell-formula
  • Process office data

Example: Set the value of an excel-cell

ActiveSheet.Cells("A1").Value = "Foo"

VBC and -.NET are no script languages. You use them to write standalone-applications with separate IDE's which you can't do with VBA (VBA-scripts just "exist" in Office)

VBA has nothing to do with VB.NET (they just have a similar syntax).

0
11

Actually VBA can be used to compile DLLs. The Office 2000 and Office XP Developer editions included a VBA editor that could be used for making DLLs for use as COM Addins.

This functionality was removed in later versions (2003 and 2007) with the advent of the VSTO (VS Tools for Office) software, although obviously you could still create COM addins in a similar fashion without the use of VSTO (or VS.Net) by using VB6 IDE.

1
  • 11
    This functionality was not removed. Microsoft just didn't update "Office XP Developer" to support later versions. You can still install developer and it works without problems. It just not not supported by Microsoft. This is because VBA that ships with 2003/2007 is still that same VBA version as XP/2002.
    – AMissico
    Commented Mar 5, 2010 at 14:30
6

It's VBA. VBA means Visual Basic for Applications, and it is used for macros on Office documents. It doesn't have access to VB.NET features, so it's more like a modified version of VB6, with add-ons to be able to work on the document (like Worksheet in VBA for Excel).

1
  • 7
    No, VBA is not a modified version of VB5/6 -- rather, it's a subset. Take a look at the Object Browser in the VB5/6 IDE, and you'll see the complete VBA object library there to use and abuse. That said, VBA does (typically, though not necessarily) have additional object libraries that load by default, and provide global objects by default, which relate to the host environment du jour. Commented Jun 16, 2009 at 1:00
4

VBA stands for Visual Basic For Applications and its a Visual Basic implementation intended to be used in the Office Suite.

The difference between them is that VBA is embedded inside Office documents (its an Office feature). VB is the ide/language for developing applications.

4

VB is not a language. VB is a program that hosts VBA, just as Office hosts VBA. VB is a set of App objects, just like Word and Excel have, and a forms package, just like in Office.

So you can only write VBA code in VB.

PS this info is on the INFO tab on the VB question page for VB.

From VBA Info

VBA 6, was shipped in 1998 and includes a myriad of licensed hosts, among them: Office 2000 - 2010, AutoCAD, PI Processbook, and the stand-alone Visual Basic 6.0

2
  • 3
    This answer is plain wrong. VBA is not VB6, those are distinct entities that share many features. That short quote doesn't prove anything. Saying it's not a language because it runs on a host also condemns languages such as JavaScript to non-languages, which is just plain not true. Also, VB6 programs can be compiled into stand-alone programs, which makes them not require any host (besides Windows, that is).
    – Erik A
    Commented Jul 4, 2018 at 20:36
  • @ErikA No you have misunderstood what they are saying. VB as in VB6 is the Host Application that runs VBA, just as Office applications do. VB6 just happens to be an application that allows you to release binaries to create stand-alones. There are other answers above that explain the details.
    – MILO
    Commented Oct 3, 2019 at 3:31
1

VB (Visual Basic only up to 6.0) is a superset of VBA (Visual Basic for Applications). I know that others have sort of eluded to this but my understanding is that the semantics (i.e. the vocabulary) of VBA is included in VB6 (except for objects specific to Office products), therefore, VBA is a subset of VB6. The syntax (i.e. the order in which the words are written) is exactly the same in VBA as it would be in VB6, but the difference is the objects available to VBA or VB6 are different because they have different purposes. Specifically VBA's purpose is to programatically automate tasks that can be done in MS Office, whereas VB6's purpose is to create standard EXE, ActiveX Controls, ActiveX DLLs and ActiveX EXEs which can either work stand alone or in other programs such as MS Office or Windows.

1
  • VB6 hosts the VBA language. It is identical. VB6, as host, provides certain objects as Word does when its hosting.
    – ACatInLove
    Commented Feb 7, 2018 at 2:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.