Notes in Hindi

About VBA Forms

Makhanlal Chaturvedi University / BCA / VBA programming

VBA Forms Overview and Implementation Guide in Hindi

About VBA Forms in Hindi

Introduction to VBA Forms and their purpose in Hindi

VBA Forms, जिन्हें हम UserForms भी कहते हैं, Microsoft Excel के अंदर Visual Basic for Applications (VBA) में एक बहुत ही ज़रूरी feature होता है। ये Forms एक तरह का interface होते हैं जहाँ पर user से input लिया जा सकता है, और उसी input के आधार पर Excel में कार्य किया जा सकता है।

जैसे मान लीजिए कोई student registration form बनाना है, जिसमें Name, Age, Class जैसे field भरवाने हों, तो Excel worksheet में manually सब कुछ करवाने की बजाय एक Form बनाया जा सकता है जहाँ user सीधे input दे सके। इस तरह के Form को ही हम VBA Form कहते हैं।

VBA Forms का मुख्य उद्देश्य होता है Excel के अंदर user-interactive interface प्रदान करना, जिससे कोई भी व्यक्ति बिना formula या worksheet structure बदले, एक structured तरीके से डेटा enter कर सके।

  • VBA Form एक user-defined GUI (Graphical User Interface) होता है।
  • इसमें अलग-अलग controls जैसे TextBox, Label, Button, ComboBox, आदि का उपयोग किया जाता है।
  • इसका प्रयोग डेटा entry को आसान और professional बनाने के लिए किया जाता है।

How to create and design VBA Forms in Hindi

VBA Forms बनाने के लिए आपको Excel में Visual Basic Editor (VBE) का इस्तेमाल करना होता है। नीचे एक beginner-friendly step-by-step प्रक्रिया दी गई है जिससे आप अपना पहला VBA Form बना सकते हैं:

  • Excel खोलें और ALT + F11 दबाकर Visual Basic Editor खोलें।
  • Insert menu पर जाएं और UserForm चुनें।
  • अब आपके सामने एक खाली Form खुलेगा। इस Form में आप Tools Box से controls को drag करके ला सकते हैं।
  • Form का नाम बदलने के लिए properties window में (Name) property को बदलें।

अब हम एक basic registration form design करेंगे जिसमें निम्नलिखित fields होंगे:

Field Name Control Type
Name TextBox
Age TextBox
Gender ComboBox
Submit CommandButton

इन सभी controls को ToolsBox से drag करके Form में arrange करें और उनके properties जैसे Name, Caption, Font को customize करें।

Using controls and events in VBA Forms in Hindi

VBA Form के अंदर controls (जैसे TextBox, Button, आदि) का प्रयोग केवल visual रूप से नहीं होता, बल्कि इन्हें कोड के माध्यम से logical रूप से भी control किया जाता है। जब कोई user किसी Button पर click करता है या किसी TextBox में input भरता है, तो वह एक event होता है। उस event पर हमें कुछ कोड run कराना होता है।

जैसे मान लीजिए हमने एक CommandButton (Submit Button) पर click करते समय, सभी field का डेटा Excel sheet में भेजना है:

Private Sub CommandButton1_Click()
  Dim lastRow As Long
  lastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
  Sheets("Sheet1").Cells(lastRow, 1).Value = TextBox1.Value ' Name
  Sheets("Sheet1").Cells(lastRow, 2).Value = TextBox2.Value ' Age
  Sheets("Sheet1").Cells(lastRow, 3).Value = ComboBox1.Value ' Gender
  MsgBox "Data submitted successfully!"
End Sub
  • CommandButton1 Submit Button का name है।
  • TextBox1, TextBox2 और ComboBox1 user input fields हैं।
  • MsgBox एक message popup करने के लिए होता है।

Form से जुड़ी अन्य common events:

  • Initialize: जब Form पहली बार load होता है
  • Click: किसी Button पर click करने पर
  • Change: किसी TextBox या ComboBox का value बदलने पर

Practical examples of VBA Forms in Excel projects in Hindi

नीचे कुछ practical और useful real-life examples दिए गए हैं जहाँ VBA Forms का उपयोग करके Excel को powerful बनाया जा सकता है:

  • Student Registration System: UserForm के माध्यम से student की जानकारी भरना, जैसे Name, Age, Class और Excel sheet में save करना।
  • Leave Application Form: किसी company में employee leave request करने के लिए एक Form बनाया जा सकता है।
  • Inventory Entry Form: किसी दुकानदार के लिए stock entry करने का एक आसान और तेज़ तरीका।
  • Feedback Form: किसी survey या feedback के लिए structured data entry करवाना।

Example: एक Leave Application Form कोड structure:

Private Sub SubmitButton_Click()
  Dim row As Long
  row = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row + 1
  Sheet1.Cells(row, 1).Value = EmpName.Text
  Sheet1.Cells(row, 2).Value = FromDate.Value
  Sheet1.Cells(row, 3).Value = ToDate.Value
  Sheet1.Cells(row, 4).Value = Reason.Text
  MsgBox "Leave application submitted successfully!"
End Sub

इन Forms को आप Excel project में उपयोग करके अपने daily task को professional बना सकते हैं और user से बिना error के input ले सकते हैं।

Note: यदि आप चाहें तो इन Forms को Excel Open होने पर ही खुद से popup कराने के लिए Workbook Open event में कोड लिख सकते हैं:

Private Sub Workbook_Open()
  UserForm1.Show
End Sub

FAQs

VBA Form एक UserForm होता है जो Excel में user से input लेने के लिए use किया जाता है। यह एक graphical interface होता है जिसमें TextBox, Label, ComboBox, और Button जैसे controls होते हैं जो data entry को आसान बनाते हैं।
Excel में UserForm बनाने के लिए ALT + F11 दबाकर VBA Editor खोलें, फिर Insert मेनू में जाकर UserForm चुनें। इसके बाद ToolsBox से TextBox, Button आदि controls को drag करके Form पर जोड़ें और उनकी properties सेट करें।
Controls वे elements होते हैं जिन्हें हम UserForm पर use करते हैं जैसे TextBox, Label, CommandButton, ComboBox आदि। ये controls user interaction को आसान और structured बनाते हैं।
किसी Button पर click करते समय code run करवाने के लिए उस button के click event में code लिखा जाता है। जैसे: Private Sub CommandButton1_Click()
  MsgBox "Form Submitted Successfully"
End Sub
हां, VBA Forms का मुख्य उपयोग Excel में data entry के लिए ही किया जाता है। User से input लेकर उसे Excel worksheet में store किया जा सकता है एक structured और error-free तरीके से।
इसके लिए Workbook_Open() event का उपयोग किया जाता है। यह कोड 'ThisWorkbook' में लिखा जाता है: Private Sub Workbook_Open()
  UserForm1.Show
End Sub

Please Give Us Feedback