判斷 VBA 巨集是否相容
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如果 Excel 檔案中的 Visual Basic for Applications (VBA) 巨集使用的所有 API,在 Apps Script 中都有直接對應項目,則視為相容。如果巨集不完全相容,您或許可以套用解決方法或調整程式碼,讓巨集與 Apps Script 搭配運作。
使用巨集轉換工具的相容性報表,判斷是否能直接自動轉換檔案,或需要調整程式碼。
產生相容性報告時,系統會為每個檔案和 API 套用下列其中一種狀態:
狀態 |
定義 |
完全支援 |
這些檔案包含的 API 在 Apps Script 中都有直接對應項目。 |
可透過變通方法支援 |
這些檔案至少包含一個可透過變通方法支援的 API。 |
需要進一步調查 |
這些檔案至少包含一個您需要檢查的 API,以判斷後續做法。舉例來說,可能沒有對應的 API,或是巨集轉換器可能未判斷出使用的 API。 |
產生相容性報告
- 在電腦上開啟 Google 雲端硬碟。
- 在右側面板中,按一下「巨集轉換器」外掛程式
。如果沒有看到側邊面板,請點選右下方的「顯示側邊面板」圖示 chevron_left。
- 按一下「新增檔案和資料夾」。巨集轉換器只會辨識 Excel 檔案。
- 選擇要分析的檔案或資料夾,然後按一下「選取」。一次選取的檔案數量少於 2,000 個。
- 如要變更相容性報告的儲存位置,請按一下「變更目標資料夾」圖示 edit,然後選取所需資料夾。否則會儲存在「我的雲端硬碟」資料夾。
- 按一下「產生報表」。
- 分析完成後,按一下「查看報告」。
查看相容性報表
根據相容性報告中的詳細資料,決定如何繼續轉換檔案。報表包含下列部分:
您也可以使用名為「APIs to investigate」(待調查的 API) 和「APIs with workarounds」(有因應措施的 API) 的工作表,逐一查看 API 的報告。
決定後續處理方式
以下是我們針對各狀態提供的建議:
狀態 |
建議 |
完全支援 |
您可以在 Apps Script 中複製 VBA API 的相同邏輯。
繼續轉換。 |
可透過變通方法支援 |
您需要編寫程式碼,將至少一個 VBA API 替換為對應的 Apps Script API。一般來說,您可以繼續進行轉換。
您可以在轉換檔案之前或之後,手動將標示為「支援但有替代方案」的 VBA API 替換為替代方案。建議您預先進行變更。
|
需要進一步調查 |
至少有一個 API 無法轉換。視該 API 在程式碼中的重要性而定,您可能無法轉換檔案。最後的評估作業應由瞭解原始 VBA 程式碼的人員執行。
如果決定轉換檔案,您需要編寫程式碼,將至少一個 VBA API 替換為 Apps Script。您可以在轉換檔案之前或之後,手動取代標示為「需要調查」的 VBA API。建議您預先進行變更。
|
評估相容性報告後,請參閱「將 VBA 巨集轉換為 Apps Script」。
相關文章
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間: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)"]]