使用 VBA 或 .NET 来使用 Office?

发布于 2024-09-03 08:17:27 字数 171 浏览 6 评论 0原文

我想要开发和自动化 Office 软件,例如“Microsoft Excel 2007”和“Microsoft Word 2007”。但我不知道如何使用 VBA 或使用 C#/.Net Framework 来执行此操作。

使用 VBA 与 .Net 框架相比有什么好处?

我应该重点学习哪一方面?

I want to develop and automate Office software like 'Microsoft Excel 2007' And 'Microsoft Word 2007'. But I do not know how to use VBA or use C#/.Net Framework to do so.

What are the benefits of using VBA vs .Net framework?

Which one should I focus on learning?

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

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

发布评论

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

评论(5

柠檬 2024-09-10 08:17:27

在办公自动化方面,VBA 和 .NET 各有优缺点。以下只是我的一些观点。该列表并不完整,只是我个人的意见,因此请随意添加/删除点。

.NET 的优点是

  • 更丰富的语言和基类库(继承、面向对象)
  • 支持类库
  • 通常更好的工具支持,例如代码分析、测试等
  • 更容易与版本控制集成

.NET 的缺点

  • 需要更多的学习
  • 更难以部署

VBA 的优点是

  • 在 Office 中本地执行的代码相当精简
  • ,不需要较慢的 COM 桥,因此通常
  • 可以使用更快的宏记录来自动生成高质量的代码

VBA 的缺点

  • 更多的是一种遗留技术,
  • 不支持现代技术和丰富的 GUI
  • 有限的工具支持

两者都有共同点

  • 可以使用 Windows API
  • 可以使用 COM

在学习和熟悉 Office 对象模型时,VBA 肯定更容易学习,特别是因为它很容易录制宏然后只需在 VBA 编辑器中进行操作即可。

最重要的是,VBA 可能最适合易于部署的小型项目,而使用 .NET,您可以利用完整的 .NET Framework 构建功能强大的附加组件,并提供丰富的用户体验。

Both, VBA and .NET have their advantages and disadvantages when it comes to Office automation. Below are just some points right from the top of my head. The list is not complete and my personal opinion, so feel free to add/remove points as you like.

Pros of .NET are

  • richer language and base class library (inheritance, object-orientation)
  • supports class libraries
  • generally better tool support, e.g. code analysis, testing, etc
  • easier to integrate with version control

Cons of .NET

  • requires more learning
  • more difficult to deploy

Pros for VBA are

  • rather slim
  • code being executed natively in Office with no need for a slower COM bridge, therefore often faster
  • macro recording can be used to automatically generate high-quality code

Cons of VBA

  • is more of a legacy technology
  • no support for a modern and rich GUI
  • limited tool support

Both have in common

  • Possible to use Windows API
  • Possible to use COM

When it comes to learning and getting familiar with the Office object models, VBA is surely easier to learn, especially because it is so easy to record a macro and then simply play around in the VBA editor.

The bottom line is that VBA probably is best suited for smaller projects that should be easy to deploy whereas with .NET you are able to build powerful add-ons making use of the complete .NET Framework and providing a rich user experience.

暮倦 2024-09-10 08:17:27

我想说,

如果您不使用 Office 套件之外的任何其他技术,请使用 VBA。

如果您打算处理创建 xml 文件、使用数据库连接、多线程等事务,.NET 更好。

此外,展望未来也很好。您是否打算成为一名开发人员(选择 .NET),或者您只是一个高效的人,想要充分利用 Office(选择 VBA)。

I would say

if you won't use any other technologies than Office suite - go for VBA.

if you're planning to deal with things like creating xml files, using database connections, multiple threads etc. - .NET is better.

Additionally its good to look in the future. Are you planning to make career as a developer (go for .NET), or you're just productive type of person, who would like to make most of Office (go for VBA).

烟─花易冷 2024-09-10 08:17:27

看待它的一种方法是,将其视为使用露营车露营与使用第五轮拖车和 F-350 牵引的露营之间的区别。

如果戴夫和贝蒂有一辆露营车 (Excel),它会配备他们周末偶尔去海滩旅行所需的一切,以及“足够好”的 4 缸发动机 (VBA),让他们往返。

但也许布巴希望被视为一名认真的露营者。他想要更多的灵活性,可以在一年中的任何时间、任何他想去的地方露营,并携带任何他想要的东西、任何人和任何东西,包括船和狗。因此,他将购买 F-350(Visual Studio),以及一个可以拉动露营车、船、滑雪橇和马的挂钩,以及第五轮的床硬件 - 以防万一。他喜欢花时间在车库里把一切都安排好,让一切都能很好地协同工作。 C#/.Net 非常适合这一切。您需要或想要的各种尺寸的绞车和制冷装置都可以完美安装。

而且他们可以用当地的车轮牵引露营车。

One way to look at it is to view it as the difference between going camping with a camper van and going camping with a fifth-wheel trailer and an F-350 to haul it with.

If Dave and Betty have a camper van (Excel), it comes with everything they need for an occasional trip to the beach for the weekend, and a "good-enough" 4-cylinder engine (VBA) to get them there and back.

But maybe Bubba wants to be viewed as a serious Camper. He'll want lots more flexibility to camp anywhere he wants to go, any time of the year, and take anything and anyone and anything he wants along, including the boat and the dog. So he'll buy the F-350 (Visual Studio), and a hitch that will pull campers, boats, skidoos, and horses, and the bed hardware for the fifth wheel - just in case. And he loves to spend time in the garage setting everything up to work together nicely. C#/.Net is great for all that. Every size winch and refrigeration unit you'll ever need or want will fit right in.

And they can tow the camper van along for local wheels.

飘过的浮云 2024-09-10 08:17:27

这很大程度上取决于问题的复杂程度。如果事情很简单,一个快速的 VBA 脚本可能就足够了。但如果代码超过几十行,我会选择 C# / .NET。这些技术显然是 Microsoft 的战略方向,我发现使用该技术堆栈比尝试使用 VBA 执行复杂的操作可以提高工作效率。

It largely depends on how complex the problem is. If it is a simple thing, a quick VBA script might be enough. But if it is anything more than a few dozen lines of code I would opt for C# / .NET. Those technologies are clearly the strategic direction for Microsoft, and I find that you can be much more productive in that technology stack versus trying to do complicated things using VBA.

等你爱我 2024-09-10 08:17:27

如果您几乎没有编程经验,我建议您使用 VBA,原因如下。

  • 您会很快得到结果。
  • 您的学习曲线将会更短。
  • 您可以使用宏录制器来学习该语言。
  • 该语言有很大的支持基础。

正如 Steve Roman 在他的一本 Word Macro 书中指出的那样,VBA 是开始学习一般编程的绝佳语言。不,您不会学习 OOP,但您将在一个简单、不令人生畏的环境中学习过程编程、变量、类型、对象等等。

I suggest using VBA if you have little to no programming experience and here's why.

  • You will get quick results.
  • You will have a shorter learning curve.
  • You can use the macro recorder to learn the language.
  • There's a large support base for the language.

Just as Steve Roman pointed out in one of his Word Macro books, VBA is an excellent language to begin learning programming in general. No, you won't learn OOP, but you will learn procedural programming, variables, types, objects and much more in a simple, non-intimidating environment.

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