使用 VBA 或 .NET 来使用 Office?
我想要开发和自动化 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在办公自动化方面,VBA 和 .NET 各有优缺点。以下只是我的一些观点。该列表并不完整,只是我个人的意见,因此请随意添加/删除点。
.NET 的优点是
.NET 的缺点
VBA 的优点是
VBA 的缺点
两者都有共同点
在学习和熟悉 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
Cons of .NET
Pros for VBA are
Cons of VBA
Both have in common
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.
我想说,
如果您不使用 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).
看待它的一种方法是,将其视为使用露营车露营与使用第五轮拖车和 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.
这很大程度上取决于问题的复杂程度。如果事情很简单,一个快速的 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.
如果您几乎没有编程经验,我建议您使用 VBA,原因如下。
正如 Steve Roman 在他的一本 Word Macro 书中指出的那样,VBA 是开始学习一般编程的绝佳语言。不,您不会学习 OOP,但您将在一个简单、不令人生畏的环境中学习过程编程、变量、类型、对象等等。
I suggest using VBA if you have little to no programming experience and here's why.
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.