tags:

views:

2840

answers:

6

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 ?

+2  A: 

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

streetpc
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.
Karl E. Peterson
+1  A: 

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.

Victor
+6  A: 

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.

fretje
Hm, he did not even ask about VB.NET...
Tomalak
Actually, Microsoft refers to VB.Net as "Visual Basic". See http://msdn.microsoft.com/en-us/vbasic/default.aspx.
DOK
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
@Tomalak: That's why I just *Noted* that ;-)
fretje
@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
+1  A: 

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

Dario
+15  A: 

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.

Tomalak
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
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.
Dick Kusleika
Which is why I think it's worth adding that opening an Office Document carries nearly the same risk as opening an executable.
Oorang
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).
Karl E. Peterson
+1 I'll vouch for the handle bit. Getting the handle of a control in Excel that didn't provide a HWND property is just plain painful and frustrating.
Oorang
+3  A: 

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 functionaltiy was removed in later versions (2003 and 2007) with the advent of the VSTO software, although obviously you could still create COM addins in a simliar fashion without the sue of VSTO (or VS.Net) by using VB6 IDE.

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