Office 2003 和 2007 之间的 VBA 版本有区别吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1021571/
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
Is there a difference in VBA versions between office 2003 and 2007?
提问by Faisal Vali
Can I use access 2007 VBA references with impunity (specifically, as far as the base language and old com interfaces are concerned) to develop VBA based solutions for access 2003?
我可以不受惩罚地使用 access 2007 VBA 引用(特别是就基本语言和旧的 com 接口而言)来开发基于 VBA 的 access 2003 解决方案吗?
Or is there some new/modified syntax added to the language that i need to be aware of?
或者是否有一些新的/修改的语法添加到我需要注意的语言中?
Has the object model been enhanced drastically in office 2007?
对象模型在 Office 2007 中是否得到了显着增强?
Any other caveats?
还有其他注意事项吗?
Thank you.
谢谢你。
回答by Dirk Vollmar
The VBA language itself has not been changed between the recent versions of Microsoft Office (and is probably not going to change in the future either). The version of VBA from Access2000 onwards is VBA6.
VBA 语言本身在最近版本的 Microsoft Office 之间没有改变(将来也可能不会改变)。从 Access2000 开始的 VBA 版本是 VBA6。
The object model of the Office applications however is slighty modified. Microsoft usually only extends the OM by additional methods and properties. As far as Access is concerned, I cannot give you any details but you will find a list of modifications here:
然而,Office 应用程序的对象模型略有修改。Microsoft 通常仅通过其他方法和属性来扩展 OM。就 Access 而言,我无法提供任何详细信息,但您可以在此处找到修改列表:
- Object Model Changes Since Microsoft Office 2003(Access Developer Reference)
- New Objects, Collections, and Enumerations
- 自 Microsoft Office 2003 以来的对象模型更改(Access 开发人员参考)
- 新对象、集合和枚举
In general, VBA solutions developed against a certain version of Office will work with a newer version. The devil lies in the details though. Due to bug fixing and new features the applications might behave slightydifferent than the older version. The only way to find out if everything still works is exhaustive testing.
通常,针对特定版本的 Office 开发的 VBA 解决方案适用于较新的版本。然而,魔鬼在于细节。由于bug修复和新功能的应用程序的行为可能略低比旧版本不同。确定一切是否仍然有效的唯一方法是进行详尽的测试。
回答by Paulo Buchsbaum
There is some new properties, methods and objects in Excel 2007.
Excel 2007 中有一些新的属性、方法和对象。
However, most programs in Excel 2003 works well in Excel 2007
但是,Excel 2003 中的大多数程序在 Excel 2007 中运行良好
There are few stuff from VBA Excel 2003 that doesn't works at Excel 2007.
VBA Excel 2003 中的一些东西在 Excel 2007 中不起作用。
I've found 4 issues.
我发现了4个问题。
"Chart.Add" give automation error in Excel 2007 when there are more than 1 cell selected
Error don't reset by itself, it's necessary uses Err.clear before command that could be release a error.
On Error Resume Next Intruction_That_Could_be_buggy_1 if Err.Number <>0 Then Err.Clear ' <<<<==== This command is necessary Intruction_That_Could_be_buggy_2 if Err.Number <>0 Then ....
Range(...).Paste(xlFormulas) now stops when exists a possible name conflict, it's necessary to use
Application.displayalerts = False Range(....).Paste(xlFormulas) Application.displayalerts = True
Several hotkeys like Alt+N are reserved in Excel 2007. Application.Onkey("%n","rotina") doesn't works in that case. Now it's many ribbon shortcut in the ALT+Letra style. I cannot found any way to suppress this behaviour. It should be used other hotkey instead.
"Chart.Add" give automation error in Excel 2007 when there are more than 1 cell selected
错误不会自行重置,必须在可能释放错误的命令之前使用 Err.clear。
On Error Resume Next Intruction_That_Could_be_buggy_1 if Err.Number <>0 Then Err.Clear ' <<<<==== This command is necessary Intruction_That_Could_be_buggy_2 if Err.Number <>0 Then ....
Range(...).Paste(xlFormulas) 现在在存在可能的名称冲突时停止,有必要使用
Application.displayalerts = False Range(....).Paste(xlFormulas) Application.displayalerts = True
在 Excel 2007 中保留了几个热键,如 Alt+N。Application.Onkey("%n","rotina") 在这种情况下不起作用。现在它有很多 ALT+Letra 样式的功能区快捷方式。我找不到任何方法来抑制这种行为。应该使用其他热键。
回答by Terrell Miller
If you are compiling your accdb/mdb to accde/mde, you want to make sure you compile them in the same version as your main applicaiton. I've had some trouble using Access 2003 MDE's with Access 2007 (and obviously vice versa).
如果您将 accdb/mdb 编译为 accde/mde,您需要确保在与主应用程序相同的版本中编译它们。我在将 Access 2003 MDE 与 Access 2007 一起使用时遇到了一些麻烦(反之亦然)。