简体   繁体   English

MS Word VBA 在 word 2003 中保存的文档中导致 2010 64 位错误

[英]MS Word VBA in document saved in word 2003 causes error in 2010 64 bit

I have a document that has VBA macros in it and when I try to open it in word 2010 64bit it complains that the code should be updated for use on 64 bit systems.我有一个文档,其中包含 VBA 宏,当我尝试在 word 2010 64bit 中打开它时,它抱怨应该更新代码以在 64 位系统上使用。 I added conditional compilation clauses #If Not 64Bit but this did not help.我添加了条件编译子句#If Not 64Bit 但这没有帮助。 Is there anything else that might be done?还有什么可以做的吗?

Are you using any ActiveX controls?您是否使用任何 ActiveX 控件? For example, if your Word application displays a custom UserForm then it is likely that the controls on it (including some of the built-in ones) won't work properly.例如,如果您的 Word 应用程序显示一个自定义用户窗体,那么它上的控件(包括一些内置的)很可能无法正常工作。

From here :这里

ActiveX Control and COM Add-in Compatibility ActiveX 控件和 COM 插件兼容性

Existing 32-bit ActiveX controls, both third-party and Microsoft-supplied, are not compatible with the 64-bit version of Office 2010. For ActiveX controls and COM objects, there are three possible solutions:第三方和 Microsoft 提供的现有 32 位 ActiveX 控件与 64 位版本的 Office 2010 不兼容。对于 ActiveX 控件和 COM 对象,有三种可能的解决方案:

  • If you have the source code, you can generate a 64-bit version yourself,如果有源代码,可以自己生成64位版本,

  • You can contact the vendor for an updated version,您可以联系供应商获取更新版本,

  • You can search for an alternative solution.您可以搜索替代解决方案。

Native 64-bit processes in Office 2010 cannot load 32-bit binaries. Office 2010 中的本机 64 位进程无法加载 32 位二进制文件。 This includes the common controls of MSComCtl (TabStrip, Toolbar, StatusBar, ProgressBar, TreeView, ListViews, ImageList, Slider, ImageComboBox) and the controls of MSComCt2 (Animation, UpDown, MonthView, DateTimePicker, FlatScrollBar).These controls were installed by previous versions of Microsoft Office and are installed by 32-bit Office 2010. An alternative must be found for existing Microsoft Office VBA solutions that utilize these controls when the code is migrated to 64-bit Office 2010. 64-bit Office 2010 does not provide 64-bit versions of the Common Controls.其中包括 MSComCtl 的常用控件(TabStrip、Toolbar、StatusBar、ProgressBar、TreeView、ListViews、ImageList、Slider、ImageComboBox)和 MSComCt2 的控件(Animation、UpDown、MonthView、DateTimePicker)。的 Microsoft Office 并由 32 位 Office 2010 安装。必须为现有的 Microsoft Office VBA 解决方案找到替代方案,当代码迁移到 64 位 Office 2010 时使用这些控件。64 位 Office 2010 不提供 64-通用控件的位版本。


Declare statments are also affected when using the 64-bit version of Office:使用 64 位版本的 Office 时, Declare语句也会受到影响:

In previous versions of VBA, there was no specific pointer data type so the Long data type was used.在之前的 VBA 版本中,没有特定的指针数据类型,因此使用了 Long 数据类型。 And because the Long data type is always 32-bits, this breaks when used on a system with 64-bit memory because the upper 32-bits may be truncated or may overwrite other memory addresses.由于 Long 数据类型始终为 32 位,因此在具有 64 位 memory 的系统上使用时会中断,因为高 32 位可能会被截断或覆盖其他 memory 地址。 Either of these situations can result in unpredictable behavior or system crashes.这些情况中的任何一种都可能导致不可预知的行为或系统崩溃。

Example of old Declare statement:旧的Declare语句示例:

Declare Function RegOpenKeyA Lib "advapi32.dll" (ByVal Key As Long, ByVal SubKey As String, NewKey As Long) As Long

To resolve this, VBA now contains a true pointer data type: LongPtr.为了解决这个问题,VBA 现在包含一个真正的指针数据类型:LongPtr。

New version:新版本:

Declare PtrSafe Function RegOpenKeyA Lib "advapi32.dll" (ByVal Key As LongPtr, ByVal SubKey As String, NewKey As LongPtr) As Long

This data type and the new PtrSafe attribute enable you to use this Declare statement on either 32-bit or 64-bit systems.此数据类型和新的 PtrSafe 属性使您能够在 32 位或 64 位系统上使用此 Declare 语句。 The PtrSafe attribute indicates to the VBA compiler that the Declare statement is targeted for the 64-bit version of Office 2010. Without this attribute, using the Declare statement in a 64-bit system will result in a compile-time error. PtrSafe 属性向 VBA 编译器指示 Declare 语句针对 64 位版本的 Office 2010。如果没有此属性,在 64 位系统中使用 Declare 语句将导致编译时错误。 Note that the PtrSafe attribute is optional on the 32-bit version of Office 2010. This enables existing Declare statements to work as they always have.请注意,PtrSafe 属性在 32 位版本的 Office 2010 上是可选的。这使现有的 Declare 语句能够像往常一样工作。

Quotes taken from here again再次从这里引用的行情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM