新手:我应该学习 c#、VB.Net 还是 VBA/VB 来进行 excel 编程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1218601/
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-11 10:39:34  来源:igfitidea点击:

Newbie: should I learn c#, VB.Net or VBA/VB for excel programming?

c#vb.netvba

提问by NomadAlien

My background: Mostly C programming. I have some (very recently...last 2 months) acquired JAVA (novice) skills. All my limited experience is based on developing for linux.

我的背景:主要是 C 编程。我有一些(最近......过去 2 个月)获得的 JAVA(新手)技能。我所有的有限经验都是基于为 linux 开发的。

I would like to do some excel programming for work purposes. My main interest is in starting to create "dashboards" and charts/reporting from excel sheets as I'm sick and tired of updating many sheets by hand. I'm lazy so I love to automate wherever I can :-)

我想为工作目的做一些excel编程。我的主要兴趣是开始从 Excel 工作表创建“仪表板”和图表/报告,因为我厌倦了手动更新许多工作表。我很懒,所以我喜欢尽可能地自动化:-)

Which one of these "new" languages (for me) would you recommend to learn? I'm also hoping that if/when I'm getting more familiar with Windows/MS Office environment I can do more "powerfull" things.

您会推荐学习这些“新”语言中的哪一种(对我而言)?我也希望如果/当我越来越熟悉 Windows/MS Office 环境时,我可以做更多“强大”的事情。

回答by Andrew Shepherd

If your main goal is to optimise your Excel tasks, then VBA is the language to learn.

如果您的主要目标是优化 Excel 任务,那么 VBA 就是要学习的语言。

The good thing is that if you have any programming background the learning curve is extremely straightforward.

好消息是,如果您有任何编程背景,学习曲线非常简单。

Just run "Record Macro", perform a task, then look at the code that was generated. You've got a working example to learn from.

只需运行“录制宏”,执行一项任务,然后查看生成的代码。你有一个可以学习的工作示例。

回答by Jon Skeet

I personally prefer C# as a language, but in terms of releasedversions, VB.NET is a better language to use for Office interop. C# 4 has improved this situation a lotthough, with named arguments and optional parameters, ref argument faking and COM PIA linking.

我个人更喜欢 C# 作为一种语言,但就已发布的版本而言,VB.NET 是一种更适合用于 Office 互操作的语言。C#4已改善了这种情况很多虽然与命名参数和可选参数,裁判争论伪造和COM连接PIA。

If you can use C# 4, that might be the best option for you - but if you're stuck with fully released versions, you might want to go for VB.NET instead.

如果您可以使用 C# 4,那可能是您的最佳选择 - 但如果您坚持使用完全发布的版本,您可能想要转而使用 VB.NET。

回答by Dave Roberts

If you want to dig straight into excel automation, I'd stick to VBA. If you're more interested in extending your knowledge, I'd choose one of the .NET languages, probably VB.NET.

如果您想直接深入了解 excel 自动化,我会坚持使用 VBA。如果您对扩展知识更感兴趣,我会选择其中一种 .NET 语言,可能是 VB.NET。

C# seems to be more prestigious/popular, but it's also closer to what you already know. If you learn the .NET Framework using VB, that and your C/java syntax means you'll be able to read C#. It would also give a smoother transition to VBA if you change your mind.

C# 似乎更有声望/流行,但它也更接近你已经知道的。如果您使用 VB 学习 .NET Framework,那么您的 C/java 语法意味着您将能够阅读 C#。如果您改变主意,它还可以更顺利地过渡到 VBA。

回答by Andy Brown

All of the answers given are sensible, but I'm not sure they're realistic. Yes, Microsoft have been wanting to get rid of VBA for some time now, and I'm sure they dearly wish that Visual Studio Tools for Office would take off; and yes, VB.NET and C# both support something called classes (using object-orientated programming) much better than VBA does.

给出的所有答案都是合理的,但我不确定它们是否现实。是的,微软一段时间以来一直想摆脱 VBA,我相信他们非常希望 Visual Studio Tools for Office 能够起飞;是的,VB.NET 和 C# 都比 VBA 更好地支持称为类的东西(使用面向对象的编程)。

HOWEVER ... the world uses VBA! Particularly for Excel solutions, I'd guess about 99% of all systems ever written use VBA. So personally I'd learn VBA, helped by the fact that:

然而......世界使用VBA!特别是对于 Excel 解决方案,我猜想大约 99% 的所有系统都使用 VBA。因此,我个人会学习 VBA,这得益于以下事实:

  1. You can record macros to see how to do things; and
  2. It's built into Excel (no need to buy or install any other software).
  1. 可以录制宏,看看怎么做;和
  2. 它内置于 Excel 中(无需购买或安装任何其他软件)。

I've written a VBA tutorial onlinewhich I hope will help, full of example code and diagrams. Let me know what you think of it, if you should use it.

我在网上写了一个VBA 教程,希望能有所帮助,里面有很多示例代码和图表。如果您应该使用它,请告诉我您的想法。

PS It might seem that my advice is somewhwat biased, but it isn't. We train on VSTO, C# and VB.NET, and my personal preferred programming environment by some way is Visual Studio (VBA drives me mad when I have to revert to it now). However, that's the result of nearly 20 years of learning! For a new programmer, VBA is much simpler to learn.

PS 我的建议似乎有些偏颇,但事实并非如此。我们在 VSTO、C# 和 VB.NET 上进行培训,我个人偏爱的编程环境在某种程度上是 Visual Studio(当我现在不得不恢复使用 VBA 时,我很生气)。然而,那是近20年学习的结果!对于一个新的程序员来说,VBA 学起来要简单得多。

回答by FlappySocks

Since you know Java & C, C# should be the easiest to learn. More jobs for C# skills too, if that's important to you.

既然您了解 Java 和 C,那么 C# 应该是最容易学习的。C# 技能的更多工作,如果这对您很重要。

回答by Thorarin

Microsoft plans to get rid of VBA sometime in the future. Support was already dropped from the Mac version of Office 2008 for example. It way stay around in the Windows version for some time, but no significant new development will be done on it.

微软计划在未来的某个时候摆脱 VBA。例如,Office 2008 的 Mac 版本已经取消了支持。它会在 Windows 版本中停留一段时间,但不会对其进行重大的新开发。

Seeing you have C and Java knowledge, and considering you're starting fresh, I'd definitely go with .NET. It's simply the better investment for your time.

看到您拥有 C 和 Java 知识,并考虑到您是新手,我肯定会选择 .NET。这只是对您的时间更好的投资。

Like Jon Skeet says, C# (4.0) is probably your best option ifyou don't mind using beta software.

正如 Jon Skeet 所说,如果您不介意使用测试版软件,C# (4.0) 可能是您的最佳选择。