ماکروهای VBA را به Apps Script تبدیل کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
قبل از شروع
ممکن است بخواهید قبل از تبدیل فایل های خود، API های ناسازگار را در کد VBA خود به روز کنید. برای فایلهایی که وضعیت دقیقاً پشتیبانی میشوند ، میتوانید به مرحله ۱ بروید: فایلهای خود را تبدیل کنید .
APIهای VBA ناسازگار را اصلاح کنید
برای فایلهایی که وضعیت «پشتیبانی از راه حل یا بررسی نیازها» را دارند، میتوانید راهحلها و اصلاحات خود را پس از تبدیل در Apps Script اعمال کنید، اما توصیه میکنیم قبل از تبدیل فایلهایتان، ابتدا کد VBA را که با آن آشنا هستید تغییر دهید.
برای هر API که در گزارش سازگاری بهعنوان «پشتیبانیشده با راهحل یا بررسی نیاز» علامتگذاری شده است، موارد زیر را توصیه میکنیم:
- اگر عملکرد انجام شده توسط API برای عملکرد صحیح ماکرو VBA شما مهم نیست، آن را از کد VBA خود حذف کنید. اگر چنین است، کد خود را تغییر دهید تا رفتار مشابهی را با API های VBA پشتیبانی شده پیاده سازی کنید.
- برای APIهایی با وضعیت پشتیبانی شده با راه حل ، اگر نمی توانید به API های پشتیبانی شده VBA تغییر دهید، API های VBA خود را همانطور که هست رها کنید. پس از تبدیل به Apps Script، یک راه حل شناخته شده برای این API در نظرات کد Apps Script تبدیل شده توصیه می شود.
- اگر مشکل از یک ساختار زبانی اجرا نشده است، کد خود را بازنویسی کنید تا از استفاده از آن ساختارها اجتناب کنید.
برای APIهایی با وضعیت بررسی نیاز دارد ، بررسی کنید آیا کد شما حاوی یکی از APIهای زیر است:
-
Adodb.connection
-
CreateObject
: این API اغلب برای اتصال به پایگاه داده و نرم افزار برنامه ریزی منابع سازمانی استفاده می شود. -
Shell.execute
-
OleObject
اگر بله، توصیه میکنیم فایلهایی را که این APIها به آنها تعلق دارند تبدیل نکنید و گزینههای دیگر را بررسی کنید. این APIها معمولاً عملیات حیاتی را برای یک ماکرو انجام می دهند، مانند اتصال به پایگاه داده یا دسترسی به یک منبع محلی، و Apps Script به طور کلی راه حل خوبی نیست.
مرحله 1: فایل های خود را تبدیل کنید
- در رایانه، Google Drive را باز کنید.
- در پانل سمت راست، بر روی افزونه Macro Converter کلیک کنید
. اگر پانل کناری را نمیبینید، در پایین سمت چپ، روی Show side panel chevron_left کلیک کنید. - روی افزودن فایلها و پوشهها کلیک کنید. مبدل ماکرو فقط فایل های اکسل را تشخیص می دهد.
- فایل ها یا پوشه هایی را که می خواهید تبدیل کنید انتخاب کنید و روی Select کلیک کنید. کمتر از 2000 فایل را در یک زمان انتخاب کنید.
- برای تغییر مکان ذخیره فایلهای تبدیل شده، روی تغییر edit پوشه مقصد کلیک کنید و پوشه مورد نظر خود را انتخاب کنید. در غیر این صورت، فایل ها در پوشه MyDrive شما ذخیره می شوند.
- روی Convert کلیک کنید.
- وقتی تبدیل کامل شد، روی مشاهده نتایج کلیک کنید.
مرحله 2: فایل های تبدیل شده خود را تست کنید
کد Apps Script خود را اجرا کنید
پس از تبدیل فایلهای خود، عملکرد Apps Script را آزمایش کنید. فایل های تبدیل شده را با داده هایی که معمولاً با فایل های اکسل خود استفاده می کنید، آزمایش کنید. در صورت امکان، خروجی فایل های شیت های تبدیل شده خود را با خروجی فایل های اکسل اصلی خود مقایسه کنید.
محرک های خود را آزمایش کنید
اگر فایلهای شما حاوی محرکهایی مانند onOpen()
، onEdit()
یا onClick()
، تریگرهای خود را نیز آزمایش کنید. برخی از محرکهای VBA بهطور خودکار تبدیل نمیشوند و باید در Apps Script مورد بررسی قرار گیرند. به آدرس مسائل رایج مراجعه کنید.
فایل های ReadMe را مرور کنید
اگر یک فایل ReadMe با فایل تبدیل شده شما ایجاد شده است، مشکلات تبدیل فهرست شده در فایل ReadMe را بررسی کنید.
- اگر ممکن است مشکلات برای مواردی که آزمایش نکردهاید مشکل ساز باشد، تغییرات توصیه شده را در کد خود اعمال کنید.
- اگر همه سناریوهای ممکن را آزمایش کرده اید و همه چیز طبق برنامه کار می کند، احتمالاً نیازی به ایجاد تغییرات ندارید.
مرحله 3: رفع خطاها
اگر هنگام آزمایش فایل های خود با خطا مواجه شدید، به رفع خطاها در کد تبدیل شده خود مراجعه کنید.
اگر کد بدون خطا اجرا می شود، اما نتیجه آن چیزی نیست که انتظار داشتید، فایل ReadMe فایل را باز کنید. هر بخش را مرور کنید تا مشخص شود چه چیزی باعث این مشکل شده است و راه حل توصیه شده را اعمال کنید.
پس از رفع خطاها، فایل را دوباره تست کنید تا مطمئن شوید همه چیز همانطور که در نظر گرفته شده است کار می کند.
مقالات مرتبط
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe Macro Converter add-on helps you convert your VBA macros to Apps Script, allowing them to run in Google Sheets.\u003c/p\u003e\n"],["\u003cp\u003eBefore converting, review the compatibility report and modify or remove incompatible VBA APIs for better conversion results.\u003c/p\u003e\n"],["\u003cp\u003eThe conversion process involves adding files to the add-on, initiating the conversion, and then testing the converted Apps Script functions and triggers in Google Sheets.\u003c/p\u003e\n"],["\u003cp\u003eIf errors occur or the results are unexpected, consult the generated ReadMe files and the troubleshooting documentation to fix issues and ensure proper functionality.\u003c/p\u003e\n"],["\u003cp\u003eAfter successful conversion and testing, your macros will be operational within Google Sheets, leveraging the capabilities of Apps Script.\u003c/p\u003e\n"]]],[],null,["# Convert VBA macros to Apps Script\n\nBefore you begin\n----------------\n\nYou might want to update incompatible APIs in your VBA code before you convert\nyour files. For files that have the status *Supported exactly* , you can proceed\nto [Step 1: Convert your files](/apps-script/guides/macro-converter/convert-files#step_1_convert_your_files).\n\n### Modify incompatible VBA APIs\n\nFor files that have the status *Supported with workaround* or *Needs\ninvestigation*, you can apply your workarounds and fixes after the conversion\nin Apps Script, but we recommend that you modify the VBA code that you're\nfamiliar with first, before you convert your files.\n\nFor each API marked as *Supported with workaround* or *Needs investigation* in\nthe compatibility report, we recommend the following:\n\n- If the function performed by the API isn't critical to your VBA macro working properly, remove it from your VBA code. If it is, change your code to implement a similar behavior with [supported VBA APIs](/apps-script/guides/macro-converter/compatible-vba-apis).\n- For APIs with the status *Supported with workaround*, if you can't switch to supported VBA APIs, leave your VBA APIs as is. After you convert to Apps Script, a known workaround for this API is recommended in the comments of the converted Apps Script code.\n- If the issue is coming from an [unimplemented language construct](/apps-script/guides/macro-converter/fix-conversion-errors#unimplemented_language_constructs), rewrite your code to avoid using those constructs.\n- For APIs with the status *Needs investigation*, check if your code contains\n any of the following APIs:\n\n - `Adodb.connection`\n - `CreateObject`: This API is often used to connect to database and enterprise resource planning software.\n - `Shell.execute`\n - `OleObject`\n\n If yes, we recommend that you don't convert the files these APIs belong to\n and investigate other options. These APIs tend to perform critical operations\n for a macro, like connecting to a database or accessing a local resource, and\n Apps Script is generally not a good solution.\n\nStep 1: Convert your files\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 convert and click **Select**. Select fewer than 2,000 files at a time.\n5. To change where your converted files are saved, click Change destination folder edit, and select the folder you want. Otherwise, the files are saved in your MyDrive folder.\n6. Click **Convert**.\n7. When the conversion completes, click **View results**.\n\nStep 2: Test your converted files\n---------------------------------\n\n### Run your Apps Script code\n\nAfter you convert your files, test the Apps Script functions. Test the converted\nfiles with the data you normally use with your Excel files. If possible, compare\nthe output of your converted Sheets files with the output of your original Excel\nfiles.\n\n### Test your triggers\n\nIf your files contain triggers like `onOpen()`, `onEdit()`, or `onClick()`, test\nyour triggers, too. Some VBA triggers won't convert automatically and need to be\naddressed in Apps Script. See [Address common issues](/apps-script/guides/macro-converter/address-conversion-issues).\n\n### Review ReadMe files\n\nIf a ReadMe file was generated with your converted file, review the conversion\nissues listed within the ReadMe file.\n\n- If the issues might be problematic for cases you haven't tested, apply the recommended changes to your code.\n- If you've tested all possible scenarios and everything works as intended, you probably don't need to make changes.\n\nStep 3: Fix errors\n------------------\n\nIf you run into errors while testing your files, see [Fix errors in your\nconverted code](/apps-script/guides/macro-converter/fix-conversion-errors).\n\nIf the code runs without errors, but the result isn't what you expected, open\nthe file's ReadMe file. Review each section to help determine what's causing the\nissue and apply the recommended fix.\n\nAfter you fix errors, test the file again to make sure everything works as\nintended.\n\nRelated articles\n----------------\n\n- [Macro Converter add-on overview](/apps-script/guides/macro-converter/overview)\n- [Determine if VBA macros are compatible](/apps-script/guides/macro-converter/compatibility-report)\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)"]]