Visual Basic 6.0和VBA之间的区别

时间:2022-02-08 16:32:55

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.

两者有什么区别。我一直认为VBA是VB的某种“残缺”版本,但是当有一天朋友问我时,我不知道实际的差异是什么。

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

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

9 个解决方案

#1


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

对于几乎所有的编程目的,VBA和VB 6.0是相同的。

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.

VBA无法将您的程序编译为可执行二进制文件。您将始终需要主机(例如Word文件和MS Word)来包含和执行您的项目。您也无法使用VBA创建COM DLL。

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.

除此之外,IDE有所不同 - 相比之下,VB 6.0 IDE更强大。另一方面,您在VBA中紧密集成了主机应用程序。应用程序全局对象(如“ActiveDocument”)和事件在没有声明的情况下可用,因此特定于应用程序的编程是直截了当的。

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.

尽管如此,没有什么能阻止你启动Word,加载VBA IDE并解决与Word无关的问题。我不确定VB 6.0是否可以(技术上)做什么,而VBA不能。我在MSDN上寻找比较表。

#2


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.

VBA代表Visual Basic for Applications,因此是VB的小型“for applications”脚本兄弟。 VBA确实可以在Excel中使用,但也可以在其他办公应用程序中使用。

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

使用VB,可以创建一个独立的Windows应用程序,这是VBA无法实现的。

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

但是,开发人员可以将VBA“嵌入”他们自己的应用程序中,作为自动化这些应用程序的脚本语言。

Edit: From the VBA FAQ:

编辑:从VBA常见问题解答:

Q. What is Visual Basic for Applications?

问:什么是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.

答:Microsoft Visual Basic for Applications(VBA)是一个可嵌入的编程环境,旨在使开发人员能够使用Microsoft Visual Basic的全部功能构建自定义解决方案。使用托管VBA的应用程序的开发人员可以自动化和扩展应用程序功能,从而缩短自定义业务解决方案的开发周期。

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

请注意,VB.NET甚至是另一种语言,它只与VB共享语法。

#3


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:

这是对旧问题的一个更技术和彻底的答案:Visual Basic for Applications(VBA)和Visual Basic(pre -.NET)不仅仅是类似的语言,它们是相同的语言。特别:

  • 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
  • 它们具有相同的规范:与语言包含的内容及其含义的实现无关的描述。你可以在这里阅读:[MS-VBAL]:VBA语言规范

  • 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.
  • 它们具有相同的平台:它们都编译为Microsoft P-Code,后者由完全相同的虚拟机执行,该虚拟机在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):

在我去年遇到的一本旧VB参考书中,作者(Paul Lomax)甚至断言“VBA”一直是语言本身的名称,无论是用于独立应用程序还是用于嵌入式语境(如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."

“在我们进一步讨论之前,让我们澄清基本点.Visual Basic for Applications(VBA)是用于在Visual Basic(VB)中编程的语言.VB本身是一个开发环境;该环境的语言元素是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.

托管与独立:在实际中,当大多数人说“VBA”时,他们特指“在MS Office中使用时的VBA”,他们说“VB6”是指“在独立VBA的最后一个版本中使用的VBA”编译器(即Visual Studio 6)“。与MS Office捆绑在一起的IDE和编译器几乎与Visual Studio 6完全相同,但不限于它不允许编译为独立的dll或exe文件。这反过来意味着嵌入式VBA项目中定义的类无法从非嵌入式COM使用者访问,因为它们无法注册。

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.

持续开发:Microsoft停止使用Visual Studio 6生成独立的VBA编译器,因为他们切换到.NET运行时作为首选平台。但是,MS Office团队继续维护VBA,甚至从MS Office 2010开始发布带有新VM(现在称为VBA7.dll)的新版本(VBA7)。唯一的主要区别是VBA7同时具有32-和64位版本,并有一些增强功能来处理两者之间的差异,特别是在外部API调用方面。

#4


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

你想要比较VBA与VB-Classic(VB6 ..)或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:

VBA(Visual Basic for Applications)是一种嵌入在Microsoft Office应用程序中的基于vb-classic的脚本语言。我认为它的语言功能类似于VB5(它只缺少一些内置函数),但是:

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

您可以访问您编写VBA脚本的office文档,因此您可以访问

  • Write macros (=automated routines for little recurring tasks in your office-work)
  • 编写宏(=自动例程,用于办公室工作中的少量重复任务)

  • Define new functions for excel-cell-formula
  • 为excel-cell-formula定义新函数

  • Process office data
  • 处理办公室数据

Example: Set the value of an excel-cell

示例:设置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)

VBC和-.NET不是脚本语言。您可以使用它们来编写具有单独IDE的独立应用程序,而VBA无法对其进行编写(VBA脚本只在Office中“存在”)

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

VBA与VB.NET无关(它们只有类似的语法)。

#5


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.

实际上VBA可以用来编译DLL。 Office 2000和Office XP Developer版本包含一个VBA编辑器,可用于制作用作COM Addins的DLL。

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.

随着VSTO(VS Tools for Office)软件的出现,此功能在更高版本(2003和2007)中被删除,但显然您仍然可以以类似的方式创建COM插件而无需使用VSTO(或VS.Net)使用VB6 IDE。

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

这是VBA。 VBA表示Visual Basic for Applications,它用于Office文档上的宏。它无法访问VB.NET功能,因此它更像是VB6的修改版本,附加组件能够处理文档(如VBA for Excel中的Worksheet)。

#7


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

VBA代表Visual Basic For Applications及其旨在用于Office套件的Visual Basic实现。

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

它们之间的区别在于VBA嵌入在Office文档中(它是Office功能)。 VB是开发应用程序的ide /语言。

#8


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.

VB不是一种语言。 VB是托管VBA的程序,就像Office托管VBA一样。 VB是一组App对象,就像Word和Excel一样,以及一个表单包,就像在Office中一样。

So you can only write VBA code in VB.

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

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

PS此信息位于VB的VB问题页面上的INFO选项卡上。

From VBA Info

来自VBA信息

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

VBA 6于1998年发布,包括无数许可的主机,其中包括:Office 2000 - 2010,AutoCAD,PI Processbook和独立的Visual Basic 6.0

#9


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.

VB(Visual Basic最高为6.0)是VBA(Visual Basic for Applications)的超集。我知道其他人对此有所不同,但我的理解是VBA的语义(即词汇表)包含在VB6中(Office产品特有的对象除外),因此,VBA是VB6的子集。语法(即写入字的顺序)在VBA中与在VB6中完全相同,但不同之处在于VBA或VB6可用的对象是不同的,因为它们具有不同的目的。具体来说,VBA的目的是以编程方式自动执行可在MS Office中完成的任务,而VB6的目的是创建标准EXE,ActiveX控件,ActiveX DLL和ActiveX EXE,它们可以独立工作,也可以在其他程序(如MS Office或Windows)中工作。

#1


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

对于几乎所有的编程目的,VBA和VB 6.0是相同的。

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.

VBA无法将您的程序编译为可执行二进制文件。您将始终需要主机(例如Word文件和MS Word)来包含和执行您的项目。您也无法使用VBA创建COM DLL。

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.

除此之外,IDE有所不同 - 相比之下,VB 6.0 IDE更强大。另一方面,您在VBA中紧密集成了主机应用程序。应用程序全局对象(如“ActiveDocument”)和事件在没有声明的情况下可用,因此特定于应用程序的编程是直截了当的。

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.

尽管如此,没有什么能阻止你启动Word,加载VBA IDE并解决与Word无关的问题。我不确定VB 6.0是否可以(技术上)做什么,而VBA不能。我在MSDN上寻找比较表。

#2


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.

VBA代表Visual Basic for Applications,因此是VB的小型“for applications”脚本兄弟。 VBA确实可以在Excel中使用,但也可以在其他办公应用程序中使用。

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

使用VB,可以创建一个独立的Windows应用程序,这是VBA无法实现的。

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

但是,开发人员可以将VBA“嵌入”他们自己的应用程序中,作为自动化这些应用程序的脚本语言。

Edit: From the VBA FAQ:

编辑:从VBA常见问题解答:

Q. What is Visual Basic for Applications?

问:什么是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.

答:Microsoft Visual Basic for Applications(VBA)是一个可嵌入的编程环境,旨在使开发人员能够使用Microsoft Visual Basic的全部功能构建自定义解决方案。使用托管VBA的应用程序的开发人员可以自动化和扩展应用程序功能,从而缩短自定义业务解决方案的开发周期。

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

请注意,VB.NET甚至是另一种语言,它只与VB共享语法。

#3


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:

这是对旧问题的一个更技术和彻底的答案:Visual Basic for Applications(VBA)和Visual Basic(pre -.NET)不仅仅是类似的语言,它们是相同的语言。特别:

  • 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
  • 它们具有相同的规范:与语言包含的内容及其含义的实现无关的描述。你可以在这里阅读:[MS-VBAL]:VBA语言规范

  • 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.
  • 它们具有相同的平台:它们都编译为Microsoft P-Code,后者由完全相同的虚拟机执行,该虚拟机在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):

在我去年遇到的一本旧VB参考书中,作者(Paul Lomax)甚至断言“VBA”一直是语言本身的名称,无论是用于独立应用程序还是用于嵌入式语境(如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."

“在我们进一步讨论之前,让我们澄清基本点.Visual Basic for Applications(VBA)是用于在Visual Basic(VB)中编程的语言.VB本身是一个开发环境;该环境的语言元素是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.

托管与独立:在实际中,当大多数人说“VBA”时,他们特指“在MS Office中使用时的VBA”,他们说“VB6”是指“在独立VBA的最后一个版本中使用的VBA”编译器(即Visual Studio 6)“。与MS Office捆绑在一起的IDE和编译器几乎与Visual Studio 6完全相同,但不限于它不允许编译为独立的dll或exe文件。这反过来意味着嵌入式VBA项目中定义的类无法从非嵌入式COM使用者访问,因为它们无法注册。

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.

持续开发:Microsoft停止使用Visual Studio 6生成独立的VBA编译器,因为他们切换到.NET运行时作为首选平台。但是,MS Office团队继续维护VBA,甚至从MS Office 2010开始发布带有新VM(现在称为VBA7.dll)的新版本(VBA7)。唯一的主要区别是VBA7同时具有32-和64位版本,并有一些增强功能来处理两者之间的差异,特别是在外部API调用方面。

#4


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

你想要比较VBA与VB-Classic(VB6 ..)或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:

VBA(Visual Basic for Applications)是一种嵌入在Microsoft Office应用程序中的基于vb-classic的脚本语言。我认为它的语言功能类似于VB5(它只缺少一些内置函数),但是:

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

您可以访问您编写VBA脚本的office文档,因此您可以访问

  • Write macros (=automated routines for little recurring tasks in your office-work)
  • 编写宏(=自动例程,用于办公室工作中的少量重复任务)

  • Define new functions for excel-cell-formula
  • 为excel-cell-formula定义新函数

  • Process office data
  • 处理办公室数据

Example: Set the value of an excel-cell

示例:设置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)

VBC和-.NET不是脚本语言。您可以使用它们来编写具有单独IDE的独立应用程序,而VBA无法对其进行编写(VBA脚本只在Office中“存在”)

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

VBA与VB.NET无关(它们只有类似的语法)。

#5


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.

实际上VBA可以用来编译DLL。 Office 2000和Office XP Developer版本包含一个VBA编辑器,可用于制作用作COM Addins的DLL。

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.

随着VSTO(VS Tools for Office)软件的出现,此功能在更高版本(2003和2007)中被删除,但显然您仍然可以以类似的方式创建COM插件而无需使用VSTO(或VS.Net)使用VB6 IDE。

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

这是VBA。 VBA表示Visual Basic for Applications,它用于Office文档上的宏。它无法访问VB.NET功能,因此它更像是VB6的修改版本,附加组件能够处理文档(如VBA for Excel中的Worksheet)。

#7


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

VBA代表Visual Basic For Applications及其旨在用于Office套件的Visual Basic实现。

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

它们之间的区别在于VBA嵌入在Office文档中(它是Office功能)。 VB是开发应用程序的ide /语言。

#8


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.

VB不是一种语言。 VB是托管VBA的程序,就像Office托管VBA一样。 VB是一组App对象,就像Word和Excel一样,以及一个表单包,就像在Office中一样。

So you can only write VBA code in VB.

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

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

PS此信息位于VB的VB问题页面上的INFO选项卡上。

From VBA Info

来自VBA信息

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

VBA 6于1998年发布,包括无数许可的主机,其中包括:Office 2000 - 2010,AutoCAD,PI Processbook和独立的Visual Basic 6.0

#9


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.

VB(Visual Basic最高为6.0)是VBA(Visual Basic for Applications)的超集。我知道其他人对此有所不同,但我的理解是VBA的语义(即词汇表)包含在VB6中(Office产品特有的对象除外),因此,VBA是VB6的子集。语法(即写入字的顺序)在VBA中与在VB6中完全相同,但不同之处在于VBA或VB6可用的对象是不同的,因为它们具有不同的目的。具体来说,VBA的目的是以编程方式自动执行可在MS Office中完成的任务,而VB6的目的是创建标准EXE,ActiveX控件,ActiveX DLL和ActiveX EXE,它们可以独立工作,也可以在其他程序(如MS Office或Windows)中工作。