确定 VBA 宏是否兼容
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如果 VBA 宏中使用的所有 API 在 Apps 脚本中都有直接对应的 API,则包含 VBA 宏的 Excel 文件被视为兼容。如果您的宏不完全兼容,您或许可以采用一些解决方法或调整代码,使其与 Apps 脚本搭配使用。
使用宏转换器的兼容性报告来确定您是否可以按原样自动转换文件,或者是否需要调整代码。
生成兼容性报告后,系统会为每个文件和 API 应用以下状态之一:
状态 |
定义 |
完全支持 |
这些文件包含的 API 在 Apps 脚本中都有直接对等项。 |
支持,但需采取变通方法 |
这些文件包含至少一个可以通过变通方法支持的 API。 |
需要进一步调查 |
这些文件包含至少一个需要您查看的 API,以便确定后续操作。例如,可能没有等效的 API,或者宏转换器可能未确定所使用的 API。 |
生成兼容性报告
- 在电脑上打开 Google 云端硬盘。
- 在右侧面板中,点击“宏转换器”插件
。
如果您没有看到侧边栏,请点击右下角的“显示侧边栏”图标 chevron_left。
- 点击添加文件和文件夹。宏转换器仅识别 Excel 文件。
- 选择要分析的文件或文件夹,然后点击选择。每次选择的文件数量不得超过 2,000 个。
- 如需更改兼容性报告的保存位置,请点击“更改目标文件夹”图标 edit,然后选择所需文件夹。否则,系统会将该文件保存在“我的云端硬盘”文件夹中。
- 点击生成报告。
- 分析完成后,点击查看报告。
查看兼容性报告
借助兼容性报告中的详细信息,您可以决定如何继续进行文件转换。您的报告包含以下部分:
您还可以使用名为 APIs to investigate 和 APIs with workarounds 的工作表,逐个 API 地查看报告。
确定后续操作
以下是我们针对每种状态的建议:
状态 |
建议 |
完全支持 |
VBA API 中的相同逻辑可在 Apps 脚本中复制。
继续转换。 |
支持,但需采取变通方法 |
您需要编写代码,将至少一个 VBA API 替换为等效的 Apps 脚本 API。一般来说,您可以继续进行转换。
您可以在转换文件之前或之后手动替换标记为支持但需采用变通方法的 VBA API。我们建议您提前进行更改。
|
需要进一步调查 |
至少有一个 API 无法转换。根据相应 API 在代码中的重要性,您可能无法转换该文件。
应由了解原始 VBA 代码的人员进行最终评估。
如果您决定转换文件,则需要编写代码来替换至少一个 VBA API(使用 Apps 脚本)。您可以在转换文件之前或之后手动替换标记为 Needs investigation 的 VBA API。我们建议您提前进行更改。
|
评估兼容性报告后,请参阅将 VBA 宏转换为 Apps 脚本。
相关文章
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eVBA macros with direct Apps Script equivalents are considered compatible and can be automatically converted using the Macro Converter add-on.\u003c/p\u003e\n"],["\u003cp\u003eThe Macro Converter's compatibility report identifies files as "Supported exactly", "Supported with workarounds", or "Needs more investigation", guiding your conversion strategy.\u003c/p\u003e\n"],["\u003cp\u003eFor files needing workarounds or further investigation, manual code adjustments may be necessary before or after conversion using equivalent Apps Script APIs.\u003c/p\u003e\n"],["\u003cp\u003eThe compatibility report provides detailed analysis at the file and API level to help assess conversion feasibility and required actions.\u003c/p\u003e\n"],["\u003cp\u003eAfter reviewing the report, proceed with file conversion, addressing potential issues as outlined in the documentation.\u003c/p\u003e\n"]]],[],null,["# Determine if VBA macros are compatible\n\nAn Excel file with Visual Basic for Applications (VBA) macros is considered\ncompatible if all APIs used in the macros have a direct equivalent in Apps\nScript. If your macros aren't fully compatible, you might be able to apply\nworkarounds or adjust the code to make them work with Apps Script.\n\nUse the Macro Converter's compatibility report to determine if you can\nautomatically convert your files as-is or if you need to make adjustments to\nyour code.\n\nWhen you generate a compatibility report, one of the following statuses is\napplied to each of your files and APIs:\n\n| Status | Definition |\n|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Supported exactly** | These files contain APIs that all have direct equivalents in Apps Script. |\n| **Supported with workarounds** | These files contain at least one API that can be supported with a workaround. |\n| **Needs more investigation** | These files contain at least one API that you need to review to determine how to proceed. For instance, there might not be an equivalent API, or the Macro Converter might not have determined the API in use. |\n\nGenerate a compatibility report\n-------------------------------\n\n1. On your computer, open [Google Drive](https://drive.google.com/drive/my-drive).\n2. On the right side panel, click the Macro Converter add-on . If you don't see the side panel, at the bottom right, click Show side panel chevron_left.\n3. Click **Add files and folders**. The Macro Converter only recognizes Excel files.\n4. Choose the files or folders you want to analyze and click **Select**. Select fewer than 2,000 files at a time.\n5. To change where your compatibility report is saved, click Change destination folder edit, and select the folder you want. Otherwise, it's saved in your MyDrive folder.\n6. Click **Generate report**.\n7. When the analysis completes, click **View report**.\n\nReview the compatibility report\n-------------------------------\n\nUse the details in the compatibility report to help you decide how to proceed\nwith your file conversion. Your report includes the following sections:\n\n- **Summary**: This sheet gives an aggregated analysis of the compatibility of all submitted files and their APIs.\n- **Files - compatibility**: This sheet lists every file submitted to the Macro Converter with the compatibility status and details of each file.\n- **Files - detailed analysis**: This sheet gives more information about the\n APIs within a file and what actions you can take to successfully convert each\n API. First, from the top dropdown menu, select a file. Then, from the bottom\n dropdown menu, select a status.\n\n | **Note:** If multiple files have the same name, next to the file names, use the unique identifiers to tell the difference between them. You can open the files in Drive and look for the unique identifiers in the URLs: `https://drive.google.com/file/d/\u003cfile_identifier\u003e/view`.\n\nYou can also review the report on an API-by-API basis using the sheets called\n**APIs to investigate** and **APIs with workarounds**.\n\nDetermine how to proceed\n------------------------\n\nHere's what we recommend for each status:\n\n| Status | Recommendation |\n|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Supported exactly** | The same logic from your VBA APIs will be replicable in Apps Script. [Proceed with the conversion](/apps-script/guides/macro-converter/convert-files). |\n| **Supported with workarounds** | You need to write code to replace at least one VBA API with the equivalent Apps Script API. In general, you can proceed with the conversion. You can manually replace the VBA APIs marked as *Supported with workarounds* either before or after you convert the file. We recommend that you [make your changes beforehand](/apps-script/guides/macro-converter/convert-files#modify_incompatible_vba_apis). |\n| **Needs more investigation** | At least one API can't be converted. Depending on the importance of that API in your code, you might not be able to convert the file. Someone who understands the original VBA code should do the final evaluation. \u003cbr /\u003e If you decide to convert your file, you need to write code to replace at least one VBA API with Apps Script. You can manually replace the VBA APIs marked as *Needs investigation* either before or after you convert the file. We recommend that you [make your changes beforehand](/apps-script/guides/macro-converter/convert-files#modify_incompatible_vba_apis). |\n\nAfter you assess your compatibility report, see [Convert VBA macros to Apps\nScript](/apps-script/guides/macro-converter/convert-files).\n\nRelated articles\n----------------\n\n- [Macro Converter add-on overview](/apps-script/guides/macro-converter/overview)\n- [Convert VBA macros to Apps Script](/apps-script/guides/macro-converter/convert-files)\n- [Fix errors in your converted code](/apps-script/guides/macro-converter/fix-conversion-errors)\n- [Address common issues](/apps-script/guides/macro-converter/address-conversion-issues)\n- [Watch Macro Converter tutorials](/apps-script/guides/macro-converter/tutorials)\n- [List of compatible VBA APIs](/apps-script/guides/macro-converter/compatible-vba-apis)"]]