Modifying Menus & Toolbars in Hindi
Makhanlal Chaturvedi University / BCA / VBA programming
Modifying Menus & Toolbars in Excel VBA in Hindi
Table of Contents
Modifying Menus & Toolbars in Excel VBA in Hindi
Introduction to Modifying Menus & Toolbars in Excel VBA in Hindi
Excel VBA में हम सिर्फ cells या formulas ही automate नहीं कर सकते, बल्कि हम Excel के menus और toolbars को भी customize कर सकते हैं। इसका मतलब यह है कि हम अपने हिसाब से Excel के interface को बदल सकते हैं ताकि वह हमारे काम को और आसान बना सके। यह खास तौर पर तब बहुत काम आता है जब हम किसी कंपनी या project के लिए एक specific tool बना रहे होते हैं और चाहते हैं कि उपयोगकर्ता को सिर्फ वही चीज़ें दिखाई दें जो ज़रूरी हों।
Menus & Toolbars को customize करने के लिए Excel VBA में एक special object होता है जिसे CommandBar कहा जाता है। इसी की मदद से हम पुराने classic Excel versions (Excel 2003 और उससे पहले) के menus और toolbars को manage कर सकते हैं। नए versions (Excel 2007 से आगे) में Ribbon UI आ गया है, जिसमें थोड़ी advanced technique लगती है, लेकिन CommandBar object आज भी backward compatibility के लिए useful है।
Understanding the CommandBar object in Modifying Menus & Toolbars in Hindi
CommandBar object Excel के toolbars और menus को represent करता है। VBA में जब हम किसी menu या toolbar को access या modify करना चाहते हैं, तो हम CommandBars collection से काम लेते हैं। यह collection Excel में मौजूद सभी command bars को contain करता है।
- CommandBars: यह एक collection है जिसमें Excel की सारी command bars (toolbars और menus) होती हैं।
- CommandBar: यह individual toolbar या menu होता है जिसे हम access करते हैं।
- CommandBarControls: ये command bar के अंदर मौजूद individual buttons, dropdowns, और अन्य items होते हैं।
CommandBar object के साथ काम करते समय हम निम्न properties और methods का use करते हैं:
Application.CommandBars("Standard")– Standard toolbar को access करता है।CommandBar.Visible = True/False– किसी toolbar को दिखाने या छुपाने के लिए।CommandBar.Controls.Add– नया button या control जोड़ने के लिए।CommandBar.Delete– किसी custom toolbar को हटाने के लिए।
Accessing existing toolbars using VBA in Modifying Menus & Toolbars in Hindi
अब हम सीखेंगे कि Excel VBA से पहले से मौजूद toolbars को कैसे access किया जाए और उनमें कैसे बदलाव किए जाएं। इसका उपयोग करके हम custom buttons बना सकते हैं, extra menus जोड़ सकते हैं या किसी भी toolbar को hide/show कर सकते हैं।
1. किसी Existing Toolbar को Access करना
Sub ShowStandardToolbar()
Application.CommandBars("Standard").Visible = True
End Sub
यह कोड Excel के Standard toolbar को visible करता है। यदि यह toolbar पहले से visible है, तो कुछ नहीं होगा। इसी तरह हम "Formatting", "Chart", आदि toolbars को भी access कर सकते हैं।
2. Toolbar को Hide करना
Sub HideFormattingToolbar()
Application.CommandBars("Formatting").Visible = False
End Sub
यह code Formatting toolbar को hide कर देता है। यह तब उपयोगी होता है जब हम चाहते हैं कि user interface clean रहे या केवल custom tools दिखाई दें।
3. Custom Toolbar बनाना
Sub CreateCustomToolbar()
Dim myBar As CommandBar
On Error Resume Next
Application.CommandBars("MyToolbar").Delete
On Error GoTo 0
Set myBar = Application.CommandBars.Add(Name:="MyToolbar", Position:=msoBarTop, Temporary:=True)
With myBar.Controls.Add(Type:=msoControlButton)
.Caption = "My Button"
.Style = msoButtonCaption
.OnAction = "MyMacro"
End With
myBar.Visible = True
End Sub
इस code से एक नया toolbar "MyToolbar" नाम से बनता है, जिसमें एक button होता है। जब हम इस button पर click करेंगे, तो "MyMacro" नाम का macro चलेगा।
4. Toolbar को Delete करना
Sub DeleteCustomToolbar()
On Error Resume Next
Application.CommandBars("MyToolbar").Delete
On Error GoTo 0
End Sub
यह code "MyToolbar" को पूरी तरह से हटा देता है। इससे यह toolbar फिर Excel में नहीं दिखेगा जब तक हम उसे दुबारा create न करें।
Difference between Menu Bars and Toolbars in Modifying Menus & Toolbars in Hindi
Menu Bar और Toolbar दोनों Excel के user interface का हिस्सा होते हैं, लेकिन इन दोनों में कुछ मूलभूत अंतर होते हैं। नीचे टेबल के माध्यम से इनका अंतर समझिए:
| Feature | Menu Bar | Toolbar |
|---|---|---|
| स्थान (Position) | ऊपर horizontal line में होता है (File, Edit, View, आदि) | Menu bar के नीचे होता है |
| Items का प्रकार | Drop-down menus जिसमें options होते हैं | Buttons होते हैं जो सीधे command run करते हैं |
| Customization | Limited customization | Buttons add, remove, reposition कर सकते हैं |
| Use in VBA | CommandBars("Worksheet Menu Bar") से access होता है | CommandBars("Standard"), आदि से access होता है |
Excel VBA में आप दोनों को customize कर सकते हैं लेकिन अधिकतर उपयोग Toolbar customization के लिए किया जाता है क्योंकि toolbar में हम custom buttons, images, actions आदि आसानी से जोड़ सकते हैं।
कुछ महत्वपूर्ण बातें
- CommandBars का उपयोग Excel 2003 और उससे पहले की versions में ज्यादा होता था। Excel 2007 और आगे के versions में Ribbon UI आ गया है।
- फिर भी CommandBar object आज भी मौजूद है और कुछ चीजों को control करने के लिए उपयोगी है।
- Toolbar customization तब उपयोगी होता है जब आप किसी fixed कार्य को repeat करते हैं और उसके लिए shortcut बनाना चाहते हैं।
- Menu Bar customization थोड़ा complex होता है, लेकिन एक बार समझ में आ जाए तो यह भी उतना ही powerful होता है।
Useful VBA Commands Summary
Application.CommandBars("Standard").Visible = True– Standard toolbar को दिखाएंApplication.CommandBars("Formatting").Visible = False– Formatting toolbar को छुपाएंCommandBars.Add– नया toolbar बनाएंCommandBar.Controls.Add– नया button जोड़ेंCommandBars("MyToolbar").Delete– custom toolbar को हटाएं
इस तरह से हम Excel VBA के जरिए menus और toolbars को modify कर सकते हैं। यह functionality उन users और developers के लिए बहुत महत्वपूर्ण है जो Excel को एक professional tool की तरह इस्तेमाल करना चाहते हैं। यदि आप एक बार इसे अच्छे से सीख जाते हैं, तो आप अपने काम को बहुत speed से और automation के साथ कर सकते हैं।
FAQs
Application.CommandBars("ToolbarName").Visible = True/False का उपयोग करके किसी भी toolbar को दिखा या छुपा सकते हैं। जैसे: Application.CommandBars("Standard").Visible = True।
CommandBars.Add method का उपयोग करके एक नया toolbar बना सकते हैं और उसमें Controls.Add से custom button जोड़ सकते हैं। उदाहरण के लिए: "MyToolbar" नाम से नया toolbar बनाया जा सकता है।
CommandBars("Worksheet Menu Bar") से access किया जाता है और Toolbar को CommandBars("Standard") से।
Application.CommandBars("ToolbarName").Delete का use करके किसी भी custom toolbar को permanently delete कर सकते हैं।