Visual Basic 6.0 和 VBA 之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/993300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:50:21  来源:igfitidea点击:

Difference between Visual Basic 6.0 and VBA

vbavb6

提问by Thomas Geritzma

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 ?

采纳答案by Tomalak

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 上寻找比较表。

回答by fretje

VBA stands for Visual Basic for Applicationsand 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 的小“应用程序”脚本兄弟。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?

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.

问:什么是 Visual Basic for Applications?

答: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 共享语法。

回答by Joshua Honig

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

In an old VB reference book I came acrosslast 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 文件。这反过来意味着非嵌入式 COM 使用者无法访问在嵌入式 VBA 项目中定义的类,因为它们无法注册。

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 调用方面。

回答by Dario

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 经典的脚本语言。我认为它的语言特性类似于 VB5 的语言特性(它只是缺少一些内置函数),但是:

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

您可以访问您为其编写 VBA 脚本的办公文档,因此您可以例如

  • Write macros (=automated routines for little recurring tasks in your office-work)
  • Define new functions for excel-cell-formula
  • Process office data
  • 编写宏(=办公室工作中一些重复性任务的自动化例程)
  • 为 excel-cell-formula 定义新函数
  • 处理办公室数据

Example: Set the value of an excel-cell

示例:设置 excel 单元格的值

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 无关(它们只是具有相似的语法)。

回答by Dario

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 插件的 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)中被删除,尽管显然您仍然可以在不使用 VSTO(或 VS.Net)的情况下以类似方式创建 COM 插件使用 VB6 IDE。

回答by instanceof me

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 中的工作表)。

回答by Serenity

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代码。

PSthis info is on the INFOtab on the VB questionpage 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

回答by Victor

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/语言。

回答by user65795

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)中工作。