به مسائل رایج رسیدگی کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
مشکلات رایجی که ممکن است هنگام تبدیل کد VBA خود به Apps Script با مبدل ماکرو با آن مواجه شوید، در زیر فهرست شده است.
چاپ
API های VBA که فایل ها را چاپ می کنند به طور خودکار به Apps Script تبدیل می شوند، اما ممکن است متفاوت از API اصلی VBA رفتار کنند. در زیر دو نمونه آورده شده است:
VBA API | رفتار در اسکریپت برنامه ها | PrintOut | به Apps Script تبدیل می شود، اما Apps Script API به جای چاپگر به فایل چاپ می شود. می توانید فایل PDF را به صورت دستی چاپ کنید. |
PrintToFile | به اسکریپت برنامه ها تبدیل می شود. فایل PDF در پوشه MyDrive شما ذخیره می شود. |
موارد تبدیل نشده
ویژگی های زیر توسط مبدل ماکرو تبدیل نمی شوند و باید به صورت دستی تبدیل شوند:
محرک ها
دو نوع محرک، میانبرهای صفحه کلید و برخی از محرک های مبتنی بر رویداد، توسط مبدل ماکرو تبدیل نمی شوند. در بسیاری از موارد، می توانید این محرک ها را به صورت دستی ایجاد کنید.
میانبرهای صفحه کلید
برای افزودن میانبرهای صفحه کلید، مراحل وارد کردن توابع به عنوان ماکرو را دنبال کنید.
محرک های مبتنی بر رویداد
برخی رویدادها از کد VBA، مانند BeforeClose
یا BeforeSave
، معادلی در Apps Script ندارند، اما ممکن است بتوانید یک راه حل ایجاد کنید.
برای رویدادهایی مانند BeforeClose
، میتوانید یک منو یا دکمه سفارشی ایجاد کنید تا روی آن کلیک کنید تا عملکردی را که باید قبل از بستن صفحهگسترده انجام دهید، انجام دهید.
از آنجایی که کاربرگنگار Google هر ویرایش را بهطور خودکار ذخیره میکند، راهحلهایی برای رویدادهایی مانند BeforeSave
امکانپذیر نیست.
در VBA، UserForm یک پنجره یا کادر محاوره ای در رابط کاربری برنامه (UI) است. مبدل ماکرو UserForms را تبدیل نمی کند. می توانید آنها را به صورت دستی در Apps Script ایجاد کنید.
- در رایانه، فایل تبدیل شده را در Google Sheets باز کنید.
- در بالا، روی Extensions > ** Apps Script** کلیک کنید.
- در سمت چپ ویرایشگر کنار «Files»، روی Add a file add > HTML کلیک کنید. ما توصیه می کنیم که نام فایل HTML را با فرم اصلی VBA خود انتخاب کنید.
- فیلدها و اطلاعاتی را که می خواهید در فرم شما نمایش داده شود اضافه کنید. در مورد فرم های HTML در W3school.com بیشتر بیاموزید.
- در سمت چپ، روی فایل Apps Script (فایل GS) که کد تبدیل شده شما را دارد کلیک کنید.
- اگر قبلاً یک تریگر
onOpen()
در کد خود دارید، آن را با کد زیر به روز کنید. اگر تریگر onOpen()
در کد خود ندارید، کد زیر را اضافه کنید. function onOpen() {
SpreadsheetApp.getUi()
.createMenu('User Form')
.addItem('Show Form', 'showForm')
.addToUi();
}
function showForm() {
var html = HtmlService.createHtmlOutputFromFile('userform_module_name')
.setWidth(100)
.setTitle('Sign-up for Email Updates');
SpreadsheetApp.getUi().showSidebar(html);
}
- نام فایل HTML را که اضافه کردید جایگزین
userform_module_name
کنید. - در بالا، روی Save project save کلیک کنید.
- به Google Sheet بروید و صفحه را دوباره بارگیری کنید.
- در بالای صفحه Google، روی User Form > Show Form کلیک کنید.
محدوده های نامگذاری شده
در اکسل، محدوده های نامگذاری شده، نام هایی هستند که به یک سلول یا محدوده ای از سلول ها داده می شود.
وقتی فایل اکسل خود را به Google Sheets تبدیل می کنید، برخی از انواع محدوده های نامگذاری شده تبدیل نمی شوند زیرا پشتیبانی نمی شوند. در زیر دو نمونه آورده شده است:
محدودههای نامگذاریشده پشتیبانینشده | توضیحات | جداول | در Google Sheets پشتیبانی نمیشود، اما راهحلی دارد.
برای ایجاد مجدد این محدوده نامگذاریشده در Sheets، یک محدوده نامگذاری شده اضافه کنید که به نماد A1 محدوده جدول اشاره میکند. در کد VBA خود از همان نام محدوده با نام اصلی استفاده کنید تا کد تبدیل شده آن را تشخیص دهد. |
لیست محدوده ها | در Google Sheets پشتیبانی نمی شود. راه حلی وجود ندارد |
مقالات مرتبط
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eWhen converting VBA to Apps Script, printing functions behave differently; \u003ccode\u003ePrintOut\u003c/code\u003e prints to a file instead of directly to a printer, while \u003ccode\u003ePrintToFile\u003c/code\u003e saves the PDF to your MyDrive.\u003c/p\u003e\n"],["\u003cp\u003eThe Macro Converter does not handle certain VBA features, including some triggers, UserForms, and unsupported named ranges, requiring manual conversion.\u003c/p\u003e\n"],["\u003cp\u003eKeyboard shortcuts and some event-based triggers (like \u003ccode\u003eBeforeClose\u003c/code\u003e or \u003ccode\u003eBeforeSave\u003c/code\u003e) from VBA require manual configuration or workarounds in Apps Script due to functional differences.\u003c/p\u003e\n"],["\u003cp\u003eUserForms need to be recreated in Apps Script using HTML, and integrated into the spreadsheet through custom menus or sidebars.\u003c/p\u003e\n"],["\u003cp\u003eWhile most named ranges are converted, tables and lists of ranges require manual adjustments or are unsupported, necessitating alternative approaches in Google Sheets.\u003c/p\u003e\n"]]],[],null,["# Address common issues\n\nCommon issues you might run into when you convert your VBA code to Apps Script\nwith the Macro Converter are listed below.\n\nPrinting\n--------\n\nVBA APIs that print files are automatically converted to Apps Script, but might\nbehave differently than the original VBA API. Below are two examples:\n\n| VBA API | Behavior in Apps Script |\n|---------------|------------------------------------------------------------------------------------------------------------------------------|\n| `PrintOut` | Converts to Apps Script, but the Apps Script API prints to a file instead of a printer. You can manually print the PDF file. |\n| `PrintToFile` | Converts to Apps Script. The PDF file is saved in your MyDrive folder. |\n\nUnconverted items\n-----------------\n\nThe following features aren't converted by the Macro Converter and need to be\nconverted manually:\n\n- Some types of [Triggers](#triggers)\n- [Userforms](#userforms)\n- Unsupported types of [Named ranges](#named_ranges)\n\n### Triggers\n\nTwo types of triggers, keyboard shortcuts and some event-based triggers, aren't\nconverted by the Macro Converter. In many cases, you can create these triggers\nmanually.\n\n#### Keyboard shortcuts\n\nTo add keyboard shortcuts, follow the steps to [import functions as\nmacros](https://developers.google.com/apps-script/guides/sheets/macros#importing_functions_as_macros).\n\n#### Event-based triggers\n\nSome events from VBA code, like `BeforeClose` or `BeforeSave`, don't have\nequivalents in Apps Script, but you might be able to create a workaround.\n\nFor events like `BeforeClose`, you can create a custom menu or button to click\nto perform the action that needs to take place before you close the spreadsheet.\n\nSince Google Sheets auto-saves each edit, workarounds for events like\n`BeforeSave` aren't feasible.\n\n### Userforms\n\nIn VBA, a [*UserForm*](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/userform-object) is a window or dialog box in an application's user\ninterface (UI). The Macro Converter doesn't convert UserForms. You can manually\ncreate them in Apps Script.\n\n#### Create a user form dialogue\n\n1. On your computer, open the converted file in [Google Sheets](http://sheets.google.com).\n2. At the top, click **Extensions** \\\u003e \\*\\* Apps Script\\*\\*.\n3. At the left of the editor next to \"Files,\" click Add a file add **\\\u003e HTML**. We recommend that you give the HTML file the same name as your original VBA UserForm.\n4. Add the fields and information you want to appear in your form. Learn more about HTML forms at [W3school.com](https://www.w3schools.com/html/html_forms.asp).\n5. At the left, click the Apps Script file (GS file) that has your converted code.\n6. If you already have an `onOpen()` trigger in your code, update it with the code below. If you don't have the `onOpen()` trigger in your code, add the code below. \n\n ```gdscript\n function onOpen() {\n SpreadsheetApp.getUi()\n .createMenu('User Form')\n .addItem('Show Form', 'showForm')\n .addToUi();\n }\n function showForm() {\n var html = HtmlService.createHtmlOutputFromFile('userform_module_name')\n .setWidth(100)\n .setTitle('Sign-up for Email Updates');\n SpreadsheetApp.getUi().showSidebar(html);\n }\n \n ```\n7. Replace `userform_module_name` with the name of the HTML file you added.\n8. At the top, click Save project save.\n9. Switch to the Google Sheet and reload the page.\n10. At the top of the Google Sheet, click **User Form** \\\u003e **Show Form**.\n\n### Named ranges\n\nIn Excel, named ranges are names given to a single cell or range of cells.\n\nWhen you convert your Excel file to Google Sheets, some types of named ranges\nwon't be converted because they're not supported. Below are two examples:\n\n| Unsupported named ranges | Description |\n|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Tables | Not supported in Google Sheets, but has a workaround. \u003cbr /\u003e To recreate this named range in Sheets, add a named range that points to the A1 notation of the table range. Use the same name as the original named range in your VBA code so that the converted code recognizes it. |\n| List of ranges | Not supported in Google Sheets. There isn't a workaround. |\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- [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- [Watch Macro Converter tutorials](/apps-script/guides/macro-converter/tutorials)\n- [List of compatible VBA APIs](/apps-script/guides/macro-converter/compatible-vba-apis)"]]