Monday, 5 December 2022

Why Excel Macros Important to learn? | Macro सिखना क्यू जरुरी हैं | VBA | Excel Samadhaan

VBA Macros समय की बचत करते हैं, क्योंकि वे दोहराए जाने वाले कार्यों को स्वचालित करते हैं। यह visual basic for applications प्रोग्रामिंग कोड का एक टुकड़ा है जो एक्सेल वातावरण में चलता है, और मैक्रोज़ प्रोग्राम करने के लिए या कोड का आनंद लेने के लिये आपको कोडर ही होने की आवश्यकता नहीं है | लेकिन, मैक्रो में अपने हिसाब से changes करने के लिए आपको VBA की बेसिक knowledge होना बहुत जरुरी है।

यदि आप उत्सुक हैं कि मैक्रोज़ क्या हैं या वास्तव में उन्हें कैसे बनाया जाए, तो कोई बात नहीं - हम आपको पूरी प्रक्रिया के बारे में बताएंगे।

एक्सेल में कुछ काम होते हैं जो हम रोजाणा करते हैं। क्या यह बेहतर नहीं होगा कि एक बटन दबाने का कोई जादुई तरीका हो और हमारे रिपोर्ट के सभी नियमित कार्य चुटकियो मे हो जाएं? 
मैं आपको हाँ कहते हुए सुन रहा हूँ। 

एक्सेल में मैक्रो आपके इसी काम को हासिल करने में हमारी मदद करता है। एक नॉर्मल MIS की भाषा में कहू तो, एक्सेल में मॅक्रो आपके नियमित काम को रिकॉर्डिंग के रूप में लिख लेता है जिसे आप एक बटन का उपयोग करके फिर से चला सकते हैं।

Example के तौर पर कहू तो, आप आपके किसीं डेटा को एक्सेल में इम्पोर्ट करते हैं और उसे अपने रिपोर्ट के जरूरतो के अनुसार फॉरमॅट करते हैं। अगले दिन आपको वही सेम काम करने की आवश्यकता होगी। रोज रोज सेम काम, यह जल्द ही बोअरिंग और थकाऊ हो जाएगा। मैक्रोज़ ऐसे नियमित कार्यों को स्वचालित करके ऐसी समस्याओं का समाधान करते हैं। आप के इसी काम को रिकॉर्ड करने के लिए आप मैक्रो का उपयोग कर सकते हैं| जैसे की, डेटा इम्पोर्ट करना और अपनी रिपोर्टिंग की आवश्यकताओं को पूरा करने के लिए इसे formating करना|

 एक्सेल में मॅक्रोस एक ऐसा benefit हैं जो स्वचालित रूप से आपके लिए कोड को उत्पन्न करती हैं, आपके हर स्टेप्स को रेकॉर्ड कर कर के, Source कोड दे देती है! 

हम छोटे छोटे स्टेप्स से लेकर कॉम्प्लेक्स रिपोर्टिंग प्रक्रियाओं तक कई फाइलों के साथ सब कुछ Automated करने के लिए VBA मैक्रोज़ का उपयोग कर सकते हैं| 


Highlight Cells with Misspelled Words

Excel doesn’t have a spell check as it has in Word or PowerPoint. While you can run the spell check by hitting the F7 key, there is no visual cue when there is a spelling mistake.

Use this code to instantly highlight all the cells that have a spelling mistake in it.

'This code will highlight the cells that have misspelled words
Sub HighlightMisspelledCells()
Dim cl As Range
For Each cl In ActiveSheet.UsedRange
If Not Application.CheckSpelling(word:=cl.Text) Then
cl.Interior.Color = vbRed
End If
Next cl
End Sub

Note: that the cells that are highlighted are those that have text that Excel considers as a spelling error. In many cases, it would also highlight names or brand terms that it doesn’t understand.




How to Get Only the Numeric Part from a String in Excel

If you want to extract only the numeric part or only the text part from a string, you can create a custom function in VBA.

You can then use this VBA function in the worksheet (just like regular Excel functions) and it will extract only the numeric or text part from the string.

Something as shown below:

Dataset to get the numeric or the text part in Excel

Below is the VBA code that will create a function to extract numeric part from a string:

'This VBA code will create a function to get the numeric part from a string
Function GetNumeric(CellRef As String)
Dim StringLength As Integer
StringLength = Len(CellRef)
For i = 1 To StringLength
If IsNumeric(Mid(CellRef, i, 1)) Then Result = Result & Mid(CellRef, i, 1)
Next i
GetNumeric = Result
End Function

You need place in code in a module, and then you can use the function =GetNumeric in the worksheet.

This function will take only one argument, which is the cell reference of the cell from which you want to get the numeric part.



Similarly, below is the function that will get you only the text part from a string in Excel:

'This VBA code will create a function to get the text part from a string
Function GetText(CellRef As String)
Dim StringLength As Integer
StringLength = Len(CellRef)
For i = 1 To StringLength
If Not (IsNumeric(Mid(CellRef, i, 1))) Then Result = Result & Mid(CellRef, i, 1)
Next i
GetText = Result
End Function

So these are some of the useful Excel macro codes that you can use in your day-to-day work to automate tasks and be a lot more productive.



यदि आप एक्सेल मैक्रोज़ को सेव्ह करना चाहते हैं, तो आपको अपनी वर्कबुक को Macro-Enable टाईप में सेव करना होगा (.xlsm)

Create New Toolbar VBA

 


Option Explicit


Sub Auto_Open_ToolBar()

    Dim oToolbar As CommandBar

'    Dim oButton As CommandBarButton

    Dim oButton1 As CommandBarButton

    Dim oButton2 As CommandBarButton

    Dim MyToolbar As String


    ' Give the toolbar a name

    MyToolbar = "Macro Control"


    On Error Resume Next

    ' so that it doesn't stop on the next line if the toolbar's already there


    ' Create the toolbar; Word will error if it already exists

    Set oToolbar = CommandBars.Add(Name:=MyToolbar, _

        Position:=msoBarFloating, Temporary:=True)

    

    If Err.Number <> 0 Then

          ' The toolbar's already there, so we have nothing to do

          Exit Sub

    End If


    On Error GoTo ErrorHandler


    ' Now add a button to the new toolbar

'    Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)

'

'    ' And set some of the button's properties

'

'    With oButton

'

'         .DescriptionText = "Add The Source data for Mail Merge"

'          'Tooltip text when mouse if placed over button

'

'         .Caption = "Add The Source data for Mail Merge"

'         'Text if Text in Icon is chosen

'

'         .OnAction = "Pick_The_Source_File"

'          'Runs the Sub Pick_The_Source_File() code when clicked

'

'         .Style = msoButtonIconAndCaptionBelow

'          ' Button displays as icon, not text or both

'

'         .FaceId = 8

'          ' chooses icon #7 from the available Office icons

'

'    End With

    

    Set oButton1 = oToolbar.Controls.Add(Type:=msoControlButton)

    With oButton1


         .DescriptionText = "Run Macro to Export to PDF"

          'Tooltip text when mouse if placed over button


         .Caption = "Run Macro to Export to PDF"

         'Text if Text in Icon is chosen


         .OnAction = "Run_Confirmation"

          'Runs the Sub Run_Confirmation() code when clicked


         .Style = msoButtonIconAndCaptionBelow

          ' Button displays as icon, not text or both


         .FaceId = 7

          ' chooses icon #7 from the available Office icons


    End With

    

    

    Set oButton2 = oToolbar.Controls.Add(Type:=msoControlButton)

    With oButton2


         .DescriptionText = "Run Macro to send Mail"

          'Tooltip text when mouse if placed over button


         .Caption = "Run Macro to Send Mail"

         'Text if Text in Icon is chosen


         .OnAction = "Run_Confirmation_Outlook"

          'Runs the Sub Run_Confirmation_Outlook() code when clicked


         .Style = msoButtonIconAndCaptionBelow

          ' Button displays as icon, not text or both


         .FaceId = 6

          ' chooses icon #6 from the available Office icons


    End With


    ' Repeat the above for as many more buttons as you need to add

    ' Be sure to change the .OnAction property at least for each new button


    ' You can set the toolbar position and visibility here if you like

    ' By default, it'll be visible when created. Position will be ignored in WORD 2007 and later

    oToolbar.Top = 150

    oToolbar.Left = 150

    oToolbar.Visible = True

    

NormalExit:

    Exit Sub   ' so it doesn't go on to run the errorhandler code


ErrorHandler:

     'Just in case there is an error

     Msgbox Err.Number & vbCrLf & Err.Description

     Resume NormalExit:

End Sub


Sub Run_Confirmation()

' This code will run when you click Run_Confirmation () added above

' Add a similar subroutine for each additional button you create on the toolbar


    Dim MsgAns As String

    Dim MsgAns1 As String

    

    MsgAns = Msgbox("Do you want to Run macro?", vbQuestion + vbYesNo)


        If MsgAns = vbYes Then

            Call ExporttoPDF

        End If

        

    MsgAns1 = Msgbox("Do you want to send Mails for recently generated PDF?", vbQuestion + vbYesNo)

    

        If MsgAns1 = vbYes Then

            Call send_oulook_mail

        End If

    

End Sub

Sub Run_Confirmation_Outlook()

' This code will run when you click Run_Confirmation () added above

' Add a similar subroutine for each additional button you create on the toolbar


    Dim MsgAns As String

     

    MsgAns = Msgbox("Do you want to Run macro?", vbQuestion + vbYesNo + vbCritical)


        If MsgAns = vbYes Then

            Call send_oulook_mail

        End If

        

End Sub


Sub Delete_MyToolbar()


' Delete the unwanted toolbar that is attached to this workbook.

    Dim cmdbar As CommandBar

    For Each cmdbar In Application.CommandBars

        If cmdbar.Name = "Macro Control" Then

            cmdbar.Delete

        End If

    Next

    

End Sub








add below code in the new Class module

Option Explicit

Private Sub Document_Close()
    
    Call Delete_MyToolbar
    
End Sub

Private Sub Document_Open()

    Call Auto_Open_ToolBar
   
End Sub

featured Post

Recurring Deposite

  https://tax2win.in/guide/5-year-post-office-recurring-deposit

About Me

My photo
Kalyan, Mumbai, Maharashtra, India

Quick Search Formula