تحويل وحدات ماكرو VBA إلى "برمجة تطبيقات Google"
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
قبل البدء
قد تحتاج إلى تعديل واجهات برمجة التطبيقات غير المتوافقة في رمز VBA قبل تحويل ملفاتك. بالنسبة إلى الملفات التي تحمل الحالة متوافق تمامًا، يمكنك الانتقال إلى الخطوة 1: تحويل ملفاتك.
تعديل واجهات برمجة تطبيقات VBA غير المتوافقة
بالنسبة إلى الملفات التي تحمل الحالة متوافق مع حل بديل أو يجب التحقّق منها، يمكنك تطبيق الحلول البديلة والإصلاحات بعد التحويل في Apps Script، ولكن ننصحك بتعديل رمز VBA الذي تعرفه أولاً، قبل تحويل ملفاتك.
بالنسبة إلى كل واجهة برمجة تطبيقات تم تصنيفها على أنّها متوافقة مع حل بديل أو تحتاج إلى تحقيق في تقرير التوافق، ننصح بما يلي:
- إذا لم تكن الوظيفة التي تنفّذها واجهة برمجة التطبيقات ضرورية لعمل ماكرو VBA بشكل صحيح، يمكنك إزالتها من رمز VBA. إذا كان الأمر كذلك، غيِّر الرمز لتنفيذ سلوك مشابه باستخدام واجهات برمجة التطبيقات المتوافقة مع VBA.
- بالنسبة إلى واجهات برمجة التطبيقات التي تحمل الحالة متوافقة مع حل بديل، إذا تعذّر عليك التبديل إلى واجهات برمجة تطبيقات VBA متوافقة، يمكنك ترك واجهات برمجة تطبيقات VBA كما هي. بعد التحويل إلى "برمجة التطبيقات"، سيتم اقتراح حل بديل معروف لواجهة برمجة التطبيقات هذه في تعليقات رمز "برمجة التطبيقات" الذي تم تحويله.
- إذا كانت المشكلة ناتجة عن بنية لغوية غير متوافقة، أعِد كتابة الرمز البرمجي لتجنُّب استخدام هذه البِنى.
بالنسبة إلى واجهات برمجة التطبيقات التي تحمل الحالة يجب التحقيق فيها، تحقَّق مما إذا كان الرمز يتضمّن أيًا من واجهات برمجة التطبيقات التالية:
Adodb.connection
-
CreateObject
: تُستخدَم واجهة برمجة التطبيقات هذه غالبًا للربط بقاعدة بيانات وبرامج تخطيط موارد المؤسسة.
Shell.execute
OleObject
إذا كان الجواب نعم، ننصحك بعدم تحويل الملفات التي تنتمي إليها واجهات برمجة التطبيقات هذه، والبحث عن خيارات أخرى. تميل واجهات برمجة التطبيقات هذه إلى تنفيذ عمليات مهمة لوحدة ماكرو، مثل الاتصال بقاعدة بيانات أو الوصول إلى مورد محلي، وبشكل عام، لا تُعدّ "برمجة التطبيقات" حلاً جيدًا.
الخطوة 1: تحويل ملفاتك
- على الكمبيوتر، افتح Google Drive.
- في اللوحة الجانبية على يسار الصفحة، انقر على إضافة "محوّل وحدات الماكرو"
. إذا لم تظهر اللوحة الجانبية، انقر على رمز إظهار اللوحة الجانبية chevron_left في أسفل يسار الصفحة.
- انقر على إضافة ملفات ومجلدات. لا يتعرّف "محوّل الماكرو" إلا على ملفات Excel.
- اختَر الملفات أو المجلدات التي تريد تحويلها وانقر على اختيار. اختَر أقل من 2,000 ملف في المرة الواحدة.
- لتغيير مكان حفظ الملفات المحوّلة، انقر على "تغيير مجلد الوجهة" edit، ثم اختَر المجلد الذي تريده. بخلاف ذلك، يتم حفظ الملفات في مجلد "ملفاتي".
- انقر على تحويل.
- عند اكتمال عملية التحويل، انقر على عرض النتائج.
الخطوة 2: اختبار الملفات المحوَّلة
تشغيل رمز Apps Script
بعد تحويل ملفاتك، اختبِر دوال Apps Script. اختبِر الملفات المحوَّلة باستخدام البيانات التي تستخدمها عادةً مع ملفات Excel. إذا أمكن، قارِن بين مخرجات ملفات "جداول بيانات Google" المحوَّلة ومخرجات ملفات 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 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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)"]]