Understanding the Differences between VB and VBAVisual Basic for Applications (VBA) is Microsoft's attempt to create a common macro language for Windows products. VBA is based on the highly successful Visual Basic (VB) product. This second-generation version of Visual Basic is as easy to use as VB and shares most of its core features. Here are some of the shared features:
These features help make VBA a more robust language for shared code across multiple applications. However, VBA's ties to VB make it a mature language, even though it was first released in 1993.
Although VB and VBA are similar, they differ in some important ways. Perhaps the most important difference is the definition of the two languages. provides these definitions. Table 25.1 - Defining VB and VBA
All this is rather confusing, but there's a simple way to differentiate between VB and VBA: VB is a separate programming product that enables you to make executables, and VBA is a macro language for applications. As of VB 4.0, both products can share elements (type libraries) through the Object Browser. Using Visual Basic for Applications Starting with Visual Basic 5.0, VB has included all the features of VBA (in the form of a shared type library); code written in pure VBA can be shared across all products that use the VBA 97 type library. For example, the code in could appear in either VB or VBA. Listing 25.1 - GREETINGS.TXT - The Greetings Routine Is Compatible with Both VB and VBA Sub Greetings(YourName As String) Dim Reply As Integer Reply = MsgBox("Hello " & YourName & _ ", are you ready to compute?", vbQuestion + vbYesNo) If Reply = vbYes Then MsgBox "Well then, let's get busy!", vbInformation Else MsgBox "I'm sorry to hear that, but you must.", _ vbInformation End If End Sub From looking at the code in Listing 25.1 in its editor, it is difficult to determine which language was used. shows an example of VBA in Microsoft Excel, and shows an example of Visual Basic 5.0. Unlike in the past, viewing the editor doesn't tell you right away which product is being used, because both VBA and VB share the same common user-interface: VBE. Here is the VBA Code in Microsoft Excel 97. The same code (as shown in Figure 25.1) in Visual Basic 5.0.
|
|||||||
![]() |
![]() |
|||