从哪里开始在 Word 2007 中进行 VBA 和宏编程?

发布于 2024-09-09 05:33:48 字数 270 浏览 1 评论 0原文

我刚刚知道Word/Excel/PowerPoint 中的宏是可以编程的。这太棒了,因为我有一个包含 70 个样式表的 Word 文档。

我是一名程序员,但我不懂 VB、VBA 或 VB .NET。我对这三个感到困惑。我熟悉使用 C# 进行 .NET 编程。现在我想编写新的宏。我应该从哪里开始?什么是 VB、VBA、VB.NET?我应该学习哪一种?请推荐一些材料。

如果我学习 Word 2007,将会对其他 Office 应用程序生活、Excel 和 Excel 有所帮助。微软幻灯片软件?

I just came to know that macros in Word/Excel/PowerPoint can be programmed. That is awesome because I've a Word document with 70 tables for styling.

I'm a programmer but I don't know VB, VBA or VB .NET. I'm confused with these three. I'm familiar with .NET programming using C#. Now I want to write new macros. Where should I get started? What are VB, VBA, VB.NET and which one should I learn? Please suggest some material.

If I learn for Word 2007 will that help with other Office applications life Excel & PowerPoint?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

横笛休吹塞上声 2024-09-16 05:33:48

以下是不同 Visual Basic 的简要说明:

  • Visual Basic 6(VB6,或经典 VB)
    • 该版本于 1998 年左右发布,是 Microsoft 最初的“Visual Basic”的最后一次迭代。它具有面向对象开发的开端,但它需要 Visual Basic 运行时才能运行应用程序。许多公司已将VB6用于内部业务应用程序。它已被 VB.NET 和 .NET Framework 取代。
  • Visual Basic 应用程序 (VBA)
    • VBA 与 VB6 共享相同的代码库,并于 1996 年授权开发人员将其包含在他们自己的应用程序中。这就是 VBA 在 Microsoft Office 中的出现方式,作为一种嵌入式语言,可用于控制 Office 的各种应用程序。重要的是要记住,VBA 仍然用于编写办公应用程序,它已经有十多年的历史了,当人们习惯使用 .NET 时,可能会有这样的感觉。
  • Visual Basic .NET (VB.NET)
    • VB.NET 与 VB6 截然不同。尽管许多开发人员已按顺序引用了 VB.NET 的后续迭代(例如 VB7、VB8 等),但除了 BASIC 语法之外,VB.NET 与 VB6 和 VBA 的共同点很少。许多人认为它更像是 BASIC 的新演变,而不是 Visual Basic 的演变。因为它与 VBA 和 VB6 完全不同,所以您不能直接在 VBA 中使用 VB.NET 代码。
    • 由于 VB.NET 代码编译为与 C# 相同的托管中间语言代码,并共享相同的 .NET API,因此从编程角度来看,您可能会觉得 C# 和 VB.NET 之间的通用性比 VB6 和 VB.NET 之间的通用性更高。< /里>

如果您预计在 VBA 中进行大量开发,我强烈推荐 < em>VBA 开发人员手册,第二版,作者:Getz 和 Gilbert。

当您使用 Excel、Access 等时,学习 Word 的 VBA 语法肯定会对您有所帮助。但是,每个应用程序都有自己的 API,这些 API 提供了一组特定于其领域的对象和方法。例如,我对Excel和Access中的VBA编程非常熟悉,但我从未在Word中做过宏编程。尽管代码语法是相同的,但我必须学习 Word 的 API 才能针对它进行编程。

某些 Office 应用程序(例如 Excel)的好处是您可以录制宏,查看它生成的代码,然后调整该代码以执行您想要的操作。这很大程度上就是我开始编程的方式。

Here's a brief explanation of the different Visual Basics:

  • Visual Basic 6 (VB6, or classic VB)
    • Released around 1998, this was the last iteration of Microsoft's original "Visual Basic." It has the beginnings of object-oriented development, but it requires the Visual Basic Runtime for applications to run. A lot of companies have used VB6 for internal business applications. It was superceded by VB.NET and the .NET Framework.
  • Visual Basic for Applications (VBA)
    • VBA shares the same code base as VB6 and in 1996 was available to be licensed to developers to include in their own applications. This is how VBA appears in Microsoft Office, as an embedded language that can be used to control Office's various applications. It's important to remember that VBA, which is still used to code office applications, is over a decade old and may feel as such when one is used to working with .NET.
  • Visual Basic .NET (VB.NET)
    • VB.NET was a radical departure from VB6. Though subsequent iterations of VB.NET have been referred to in sequence (e.g. VB7, VB8, etc.) by many developers, VB.NET shares very little with VB6 and VBA other than the BASIC syntax. Many consider it more of a new evolution in BASIC rather than an evolution in Visual Basic. Because it's entirely different from VBA and VB6, you cannot not use VB.NET code directly in VBA.
    • Because VB.NET code compiles down to the same managed intermediate language code as C# and shares the same .NET APIs, you may feel more commonality between C# and VB.NET than VB6 and VB.NET from a programming perspective.

If you anticipate doing a lot of development in VBA, I would highly recommend the VBA Developer's Handbook, Second Edition, by Getz and Gilbert.

Learning the VBA syntax for Word will certainly help you when you go to use Excel, Access, etc. However, each application has its own API that provides a set of objects and methods unique to its domain. For example, I'm very familiar with programming in VBA in Excel and Access, but I have never done macro programming in Word. Although the code syntax would be the same, I'd have to learn Word's API to be able to program against it.

The nice thing about some of the Office applications (Excel, for example) is that you can record a macro, see what code it generates, and then tweak that code to do what you want. That's largely how I got started in programming.

給妳壹絲溫柔 2024-09-16 05:33:48

这里有一些很好的答案 - 我想提供另一组建议:

首先,如果您的环境支持,您可以使用 Visual Studio 2005/8/10 和您的 C# 技能通过“Visual Studio Tools”针对 Office 进行编程为办公室”。有关更多详细信息,请参阅此线程

如果您想深入研究 VBA(我个人很喜欢 VBA,因为与 VS 相比,开发速度非常快),请从这篇文章开始VBA、Visual Basic .NET 和 C# 的十种代码转换,它将向您展示所有三种语言的示例。接下来,观看此网络广播:使用 Visual Basic应用程序 (VBA) 每天都比您想象的更容易

第三- MSDN,阅读以下内容:在 Word 2010 中开始使用 VBA 。其中 99% 适用于 Word 2007。还有许多其他文章链接到此文章,或者您可以随时转到 Office VBA开发者中心作为单个跳转页面。

然后可能是时候开始直接编程了。了解其工作原理、了解 Word 的对象模型等。可以随时在 word-vba 标签下浏览 SO,看看其他人正在尝试什么要做的事和答案。

There are some good answers here - I'd like to offer one more set of suggestions:

First, if supported in your environment, you can use Visual Studio 2005/8/10 and your C# skills to program against Office with "Visual Studio Tools for Office". See this thread for more details.

If you want to delve into VBA instead (which I personally love because development is so fast compared to VS), start with this article Ten Code Conversions for VBA, Visual Basic .NET, and C# which will show you samples from all three languages. Next, watch this webcast: Using Visual Basic for Applications (VBA) Every Day Is Easier Than You Think.

Thirdly- MSDN, read through this: Getting Started with VBA in Word 2010. 99% of it applies to Word 2007. There are many other articles linked from this one or you can always go to the main page of Office VBA Developer Center as a single jump page.

Then it's probably time to get started to directly program. See how things work, learn Word's Object Model, etc. You can always browse SO under the word-vba tag to see what other people are trying to do and the answers.

酒解孤独 2024-09-16 05:33:48

您始终拥有 MSDN
如果您转到 Microsoft Word >开发商> Visual Basic 并在左侧菜单中打开 ThisDocument,您将拥有编辑器。如果按F2,您将获得可在 Microsoft Word(对象浏览器)中使用的库。最简单的程序如下:

Sub Hello()
    MsgBox "Hello World"
End Sub

当您标记了子项后,按F5(运行)。

在对象浏览器中,您将看到三个不同的对象、属性、函数和事件。当您看到引起您兴趣的内容时,请转到 单词 vba 的参考并找到它。
[如果链接发生变化,您可以在 MSDN Library > 下的树中找到它写字楼发展> 2007微软Office系统》 Word 2007 > Word 2007 开发人员参考 > Word 对象模型参考]

我认为最简单的事情就是定义一个需要解决的问题并尝试对其进行编程,类似于学习任何其他语言。不要让问题变得简单,但也不要让问题变得困难而放弃。

You always have MSDN.
If you go to Microsoft Word > Developer > Visual Basic and open up ThisDocument in the left menu, you will have the editor. If you press F2 you will get the libraries that can be used in Microsoft Word (the Object Browser). The easiest program would be the following:

Sub Hello()
    MsgBox "Hello World"
End Sub

When you have the sub marked, press F5 (to run).

In the Object Browser you will have three different objects, properties, functions and events. When you see something that strikes your interest, go to the reference for word vba and locate it.
[If the link changes, you can find it in the tree under MSDN Library > Office Development > 2007 Microsoft Office System > Word 2007 > Word 2007 Developer Reference > Word Object Model Reference]

I think the easiest thing to do is to define a problem you need fixed and try to program it, similar to learning any other language. Don't make the problem to easy, but not to hard that you give up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文