Chapter 2 - Creating Macros - Visual Basic For Applications

With the help of Visual Basic for Applications in Excel or other MS Office applications, you can automate your work, dynamically and statically, by creating macros. In last chapter, we have learned about main components in Excel VBA. Today, we will learn about creating a simple macro in VBA excel which will be executed with the help of Command Button in Active Sheet.

ایکسل یا ایم ایس آفس کی دیگر ایپلی کیشنز میں ایپلیکیشنز کے لئے ویژوول بیسک کی مدد سے ، آپ میکرو تخلیق کرکے ، متحرک اور مستحکم ، اپنا کام خود کار طریقے سے کرسکتے ہیں۔ آخری باب میں ، ہم نے ایکسل وی بی اے میں اہم اجزاء کے بارے میں سیکھا ہے۔ آج ، ہم وی بی اے ایکسل میں ایک سادہ میکرو بنانے کے بارے میں سیکھیں گے جو ایکٹو شیٹ میں کمانڈ بٹن کی مدد سے عمل میں آئیں گے۔

Developer Tab

For Creating Macros, turn on the Developer Tab by executing the below mentioned steps:

میکروز بنانے کے لئے ، درج ذیل اقدامات پر عمل کرکے ڈویلپر ٹیب کو آن کریں۔

1.    To turn on developer tab, right click on the ribbon anywhere, and then click “Customize Quick Access Toolbar or Customize the Ribbon”.

ڈویلپر ٹیب کو آن کرنے کے لئے ، کہیں بھی ربن پر دائیں کلک کریں ، اور پھر "فوری رسائی کے ٹول بار کو کسٹمائز کریں یا ربن کو اپنی مرضی کے مطابق بنائیں" پر کلک کریں۔



2.       After Clicking Customize Quick Access Toolbar or Customize the Ribbon, a pop-up dialog box will open in front of you titled “Excel Options”.

حسب ضرورت فوری رسائی ٹول بار پر کلک کرنے یا ربن کو کسٹمائز کریں کے بعد ، "ایکسل آپشنز" کے عنوان سے آپ کے سامنے ایک پاپ اپ ڈائیلاگ باکس کھل جائے گا۔



3.       Under dialog box, click the “Popular Tab” in the left side.

ڈائیلاگ باکس کے تحت ، بائیں جانب "مقبول ٹیب" پر کلک کریں۔

4.       Under Popular Tab, check the “Show Developer Tab in Ribbon”.

پاپولر ٹیب کے تحت ، "ربن میں ڈویلپر ٹیب دکھائیں" کو چیک کریں۔



5.       After check mark, click Ok.

چیک مارک کے بعد ، ٹھیک ہے پر کلک کریں۔

6.       Now, in the Main Ribbon, you will see the “Developer Tab” very next to view tab.

اب ، مین ربن میں ، آپ کو ٹیب دیکھنے کے بالکل آگے "ڈویلپر ٹیب" نظر آئے گا۔



Command Button

After executing above mentioned steps for developer tab, next step is to place a Command Button in the worksheet to execute the macros. For this execution, follow the below mentioned steps:

ڈویلپر ٹیب کے لئے مذکورہ بالا اقدامات پر عمل کرنے کے بعد ، اگلا مرحلہ میکرو کو پھانسی دینے کے لئے ورک شیٹ میں کمانڈ بٹن رکھنا ہے۔ اس عملدرآمد کے لئے ، درج ذیل اقدامات پر عمل کریں:

1.       Under Developer tab, click the Insert Button in Controls Section.

ڈویلپر ٹیب کے تحت ، کنٹرولز سیکشن میں بٹن داخل کریں پر کلک کریں۔



2.       After clicking on Insert Button, in ActiveX Controls section, click the Command Button icon.

ایکٹ ایکس ایکس کنٹرول سیکشن میں ، داخل کریں بٹن پر کلک کرنے کے بعد ، کمانڈ بٹن آئیکن پر کلک کریں۔


3.       After clicking on command button icon, hold down the ALT key with cursor for excat and accurate placement of command button.

کمانڈ کے بٹن آئیکون پر کلک کرنے کے بعد ، کمانڈ بٹن کی ایکسائٹمنٹ اور درست جگہ لگانے کے لئے ALT کی کو کرسر کے ساتھ تھامے رکھیں۔


Assign Macro

Macro is defined as the “One or more line of codes” to automate the tasks in Excel Macros VBA and in other MS Office Applications. Usually, the VBA codes lives in the modules section in excel vba editor. After executing above mentioned steps for command button, next step is to assign macro to the command button placed in the worksheet to execute the macros. For this execution, follow the below mentioned steps:

میکرو کو ایکسل میکرو وی بی اے اور ایم ایس آفس کے دوسرے ایپلی کیشنز میں کاموں کو خودکار کرنے کے لئے "کوڈز کی ایک یا ایک سے زیادہ لائن" کی تعریف کی گئی ہے۔ عام طور پر ، VBA کوڈ ایکسل وی بی اے ایڈیٹر میں ماڈیول سیکشن میں رہتے ہیں۔ کمانڈ بٹن کے لئے مذکورہ بالا اقدامات پر عمل کرنے کے بعد ، اگلا مرحلہ میکرو کو پھانسی دینے کے لئے ورک شیٹ میں رکھے گئے کمانڈ بٹن کو میکرو تفویض کرنا ہے۔ اس عملدرآمد کے لئے ، درج ذیل اقدامات پر عمل کریں:

1.       To assign macro, simply right click on command button.

میکرو تفویض کرنے کیلئے ، کمانڈ بٹن پر صرف دائیں کلک کریں۔

2.       Click view code option.

دیکھیں کوڈ آپشن پر کلک کریں۔


3.     After clicking view macro, a dialog box named “Microsoft Visual Basic for Application” will appears.

ویو میکرو پر کلک کرنے کے بعد ، "مائیکروسافٹ ویزوئل بیسک فار ایپلی کیشن" نامی ایک ڈائیلاگ باکس ظاہر ہوگا۔


4.       In Microsoft Visual Basic for Application, write the code lines in visual basic editor as shown below.

مائیکرو سافٹ ویزول بیسک فار ایپلی کیشن میں ، نیچے دکھائے گئے مطابق بصری بنیادی ایڈیٹر میں کوڈ لائنیں لکھیں۔


Note: When Microsoft Visual Basic for Application will appears, you will see window at the left side which contains the Active Sheets in Workbook, Active Workbook, Modules & User forms. That window is known as Project Explorer. If Project Explorer window does not appear, simply click view and Project Explorer.

نوٹ: جب مائیکرو سافٹ کے ایپلیکیشن برائے ایپلی کیشن ظاہر ہوگی ، آپ کو بائیں جانب ونڈو نظر آئے گا جس میں ورک بک ، ایکٹو ورک بک ، ماڈیولز اور صارف فارم میں ایکٹو شیٹس موجود ہیں۔ اس ونڈو کو پروجیکٹ ایکسپلورر کے نام سے جانا جاتا ہے۔ اگر پروجیکٹ ایکسپلورر ونڈو ظاہر نہیں ہوتی ہے تو ، صرف دیکھیں اور پروجیکٹ ایکسپلورر پر کلک کریں۔

5.       After writing the code lines in visual basic editor, close the VBA window.

بصری بنیادی ایڈیٹر میں کوڈ لائنوں کو لکھنے کے بعد ، VBA ونڈو کو بند کریں۔

6.       To run the code, simply click on the command button and you will see the result comes out in your selected range or cell.

کوڈ کو چلانے کے لئے ، صرف کمانڈ بٹن پر کلک کریں اور آپ دیکھیں گے کہ نتیجہ آپ کی منتخب کردہ حد یا سیل میں سامنے آتا ہے۔


Visual Basic Editor

To open visual basic editor, click the Visual Basic Icon shown under the developer tab. From keyboard, use the shortcut key ALT+F11 to open Visual Basic Editor.

بصری بنیادی ایڈیٹر کھولنے کے لئے ، ڈویلپر ٹیب کے نیچے دکھائے گئے بصری بنیادی شبیہ پر کلک کریں۔ کی بورڈ سے ، بصری بنیادی ایڈیٹر کھولنے کے لئے شارٹ کٹ کلید ALT + F11 کا استعمال کریں.




Comments

Popular posts from this blog

Visual Basic for Application (VBA) Introduction - Chapter 1