两者的区别是什么?我一直认为VBA是VB的“残缺”版本,但当一个朋友前几天问我,我不知道实际的区别是什么。

另外,当你使用Excel时,你用的是VB还是VBA ?


当前回答

下面是对一个老问题的更技术性和更彻底的回答:Visual Basic for Applications (VBA)和Visual Basic (pre-.NET)不仅仅是相似的语言,它们是同一种语言。具体地说:

它们具有相同的规范:对语言包含的内容及其含义的独立于实现的描述。你可以在这里阅读:[MS-VBAL]: VBA语言规范 它们具有相同的平台:它们都编译为Microsoft P-Code,后者依次由完全相同的虚拟机执行,该虚拟机在dll msvbvm[x.0].dll中实现。

在我去年读到的一本旧的VB参考书中,作者(Paul Lomax)甚至断言“VBA”一直是语言本身的名称,无论是在独立应用程序中还是在嵌入式环境中(如MS Office):

“在我们继续讨论之前,让我们先澄清一个基本问题。Visual Basic for Applications (VBA)是用于在Visual Basic (VB)中编程的语言。VB本身就是一个开发环境;该环境的语言元素是VBA。”

细微的差别

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.

其他回答

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.

VBA。VBA的意思是Visual Basic for Applications,它用于Office文档中的宏。它不能访问VB。NET特性,所以它更像是一个VB6的修改版本,附加组件能够在文档上工作(就像VBA中的Excel工作表)。

VBA是Visual Basic for Applications的缩写,它是一种用于Office Suite的Visual Basic实现。

它们之间的区别是VBA嵌入在Office文档中(这是Office的一个特性)。VB是开发应用程序的ide/语言。

下面是对一个老问题的更技术性和更彻底的回答:Visual Basic for Applications (VBA)和Visual Basic (pre-.NET)不仅仅是相似的语言,它们是同一种语言。具体地说:

它们具有相同的规范:对语言包含的内容及其含义的独立于实现的描述。你可以在这里阅读:[MS-VBAL]: VBA语言规范 它们具有相同的平台:它们都编译为Microsoft P-Code,后者依次由完全相同的虚拟机执行,该虚拟机在dll msvbvm[x.0].dll中实现。

在我去年读到的一本旧的VB参考书中,作者(Paul Lomax)甚至断言“VBA”一直是语言本身的名称,无论是在独立应用程序中还是在嵌入式环境中(如MS Office):

“在我们继续讨论之前,让我们先澄清一个基本问题。Visual Basic for Applications (VBA)是用于在Visual Basic (VB)中编程的语言。VB本身就是一个开发环境;该环境的语言元素是VBA。”

细微的差别

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.

VB不是一种语言。VB是一个承载VBA的程序,就像Office承载VBA一样。VB是一组App对象,就像Word和Excel一样,还有一个表单包,就像Office一样。

所以你只能在VB中编写VBA代码。

PS这个信息在VB问题页面的info选项卡上。

来自VBA信息

VBA 6于1998年发布,包含大量授权主机,其中包括:Office 2000 - 2010、AutoCAD、PI Processbook和独立的Visual Basic 6.0