המרת פקודות מאקרו VBA ל-Apps Script
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
לפני שמתחילים
כדאי לעדכן ממשקי API לא תואמים בקוד VBA לפני שממירים את הקבצים. אם הסטטוס של הקבצים הוא נתמך בדיוק, אפשר להמשיך אל שלב 1: המרת הקבצים.
שינוי ממשקי VBA API לא תואמים
אם הקבצים בסטטוס נתמך עם פתרון עקיף או נדרשת בדיקה, אפשר להחיל את הפתרונות העקיפים והתיקונים אחרי ההמרה ב-Apps Script, אבל מומלץ לשנות קוד VBA שאתם מכירים לפני שממירים את הקבצים.
לכל API שמסומן בדו"ח התאימות כנתמך עם פתרון עקיף או כנדרשת בדיקה, מומלץ לבצע את הפעולות הבאות:
- אם הפונקציה שמבצע ה-API לא קריטית לפעולה תקינה של מאקרו VBA, צריך להסיר אותה מקוד ה-VBA. אם כן, צריך לשנות את הקוד כדי להטמיע התנהגות דומה באמצעות ממשקי VBA API נתמכים.
- אם הסטטוס של ממשקי ה-API הוא Supported with workaround (נתמך עם פתרון עקיף), ואתם לא יכולים לעבור לממשקי VBA API נתמכים, אל תשנו את ממשקי ה-VBA API. אחרי שתמירו ל-Apps Script, תקבלו פתרון עקיף מוכר ל-API הזה בהערות של קוד Apps Script שהומר.
- אם הבעיה נובעת ממבנה שפה שלא הוטמע, צריך לשכתב את הקוד כדי להימנע משימוש במבנים האלה.
אם הסטטוס של ממשקי ה-API הוא צריך בדיקה, בודקים אם הקוד מכיל אחד מממשקי ה-API הבאים:
Adodb.connection
-
CreateObject
: משתמשים ב-API הזה לעיתים קרובות כדי להתחבר למסדי נתונים ולתוכנות לתכנון משאבים ארגוניים (ERP).
Shell.execute
OleObject
אם כן, מומלץ לא להמיר את הקבצים שממשקי ה-API האלה שייכים להם, ולבדוק אפשרויות אחרות. ממשקי ה-API האלה נוטים לבצע פעולות קריטיות עבור מאקרו, כמו התחברות למסד נתונים או גישה למשאב מקומי, ובדרך כלל Apps Script לא מהווה פתרון טוב.
שלב 1: ממירים את הקבצים
- במחשב, פותחים את Google Drive.
- בחלונית הצדדית שמשמאל, לוחצים על התוסף Macro Converter
. אם לא רואים את החלונית הצדדית, לוחצים על הסמל של הצגת החלונית הצדדית chevron_left בפינה השמאלית התחתונה.
- לוחצים על הוספת קבצים ותיקיות. הכלי Macro Converter מזהה רק קובצי Excel.
- בוחרים את הקבצים או התיקיות שרוצים להמיר ולוחצים על בחירה. בוחרים פחות מ-2,000 קבצים בכל פעם.
- כדי לשנות את המיקום לשמירת הקבצים שהומרו, לוחצים על 'שינוי תיקיית היעד' edit ובוחרים את התיקייה הרצויה. אחרת, הקבצים נשמרים בתיקייה 'אחסון שלי'.
- לוחצים על המרה.
- בסיום ההמרה, לוחצים על הצגת תוצאות.
שלב 2: בודקים את הקבצים שהומרו
הרצת קוד Apps Script
אחרי שממירים את הקבצים, בודקים את הפונקציות של Apps Script. בודקים את הקבצים שהומרו באמצעות הנתונים שבהם אתם משתמשים בדרך כלל בקובצי Excel. אם אפשר, כדאי להשוות בין הפלט של קובצי Sheets שהומרו לבין הפלט של קובצי Excel המקוריים.
בדיקת הגורמים המפעילים
אם הקבצים מכילים טריגרים כמו onOpen()
, onEdit()
או onClick()
, צריך לבדוק גם את הטריגרים. חלק מהטריגרים של VBA לא יומרו באופן אוטומטי, וצריך לטפל בהם ב-Apps Script. פתרון בעיות נפוצות
בדיקת קובצי ReadMe
אם נוצר קובץ ReadMe עם הקובץ שהומר, כדאי לעיין בבעיות ההמרה שמפורטות בקובץ ReadMe.
- אם הבעיות עלולות לגרום לבעיות במקרים שלא נבדקו, צריך להחיל את השינויים המומלצים בקוד.
- אם בדקתם את כל התרחישים האפשריים והכול פועל כמו שצריך, כנראה שלא צריך לבצע שינויים.
שלב 3: תיקון שגיאות
אם נתקלתם בשגיאות במהלך בדיקת הקבצים, כדאי לעיין במאמר תיקון שגיאות בקוד שהומר.
אם הקוד פועל ללא שגיאות, אבל התוצאה לא תואמת למה שציפיתם, פותחים את קובץ ה-ReadMe של הקובץ. כדאי לעבור על כל הקטעים כדי להבין מה גורם לבעיה וליישם את הפתרון המומלץ.
אחרי שמתקנים את השגיאות, בודקים שוב את הקובץ כדי לוודא שהכול פועל כמו שצריך.
מאמרים קשורים
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-31 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-31 (שעון UTC)."],[[["\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)"]]