简体   繁体   English

VBA 7.1向后兼容性

[英]VBA 7.1 Backwards Compatibility

I am developing some VBA code using VBA 7.1 with excel 2016 as part of a larger enterprise application (not primarily in excel). 我正在使用VBA 7.1和excel 2016开发一些VBA代码,将其作为大型企业应用程序的一部分(主要不是在excel中)。 The macros are run from a C# application and used to export data in the form of spreadsheets. 这些宏是从C#应用程序运行的,用于以电子表格的形式导出数据。 I am looking for a good guide as to what versions of excel these macros will run properly on, and where I can look for changes that could potentially cause my code to break. 我正在寻找有关这些宏将在哪些版本的excel上正确运行的良好指南,以及在哪里可以查找可能导致代码中断的更改。 I developed it using excel 2016, how backwards compatible will this be? 我是使用excel 2016开发的,这向后兼容吗?

I would like to make it compatible as far back as the 2010 excel version if possible. 如果可能的话,我想使其与2010年的excel版本兼容。

If you need compatibility with VBA6 and VBA7, this is a good example how to achieve it through compiler constants: 如果您需要与VBA6和VBA7兼容,那么这是一个很好的示例,说明如何通过编译器常量实现这一点:

Option Explicit

#If VBA6 Then
    Sub RunTheApp()
        Debug.Print "VBA6"
    End Sub
#ElseIf VBA7 Then
    Sub RunTheApp()
        Debug.Print "VBA7"
    End Sub
#Else
    Sub RunTheApp()
        Debug.Print "You cannot come here from TestMe()"
    End Sub
#End If

Sub TestMe()
    RunTheApp
End Sub

Once you try to run the TestMe module, it will print VBA6 or VBA7 , depending on your system. 尝试运行TestMe模块后,它将打印VBA6VBA7 ,具体取决于您的系统。

MSDN - Compiler Constants MSDN-编译器常量

In general, VBA7 has compability for 64bit environment. 通常,VBA7具有适用于64位环境的兼容性。 Here is the MSDN article for the differences between these two - Compatibility between the 32-bit and 64-bit Versions of Office 2010 It is a good idea to read it, if you are using external functions that are embedded in dynamic linked libraries. 这是有关这两者之间差异的MSDN文章-Office 2010的32位和64位版本之间的兼容性如果您使用的是嵌入在动态链接库中的外部函数,则最好阅读一下。

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

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