+ Reply to Thread
Results 1 to 4 of 4

One Command button for 2 macros( Not in the same time)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    One Command button for 2 macros( Not in the same time)

    Hi Is it possible to make one commandbutton run 2 different macros? I dont want them to run in the same time. When i press the button it shall run macro 1 (macro 2 is blocked), When that is finish the same button shall be able to run macro 2, and block for macro 1.
    If any one have a simple code or and example it would be nice. Using excel 2003
    Forgot to say it will be nice if the text on the button also can change, depend of which macro its ready for.

    Sincerly
    Abjac
    Last edited by abjac; 12-13-2012 at 08:53 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: One Command button for 2 macros( Not in the same time)

    You can use the text on the button to decide which code to run.
    Private Sub CommandButton1_Click()
         
           Select Case CommandButton1.Caption
                
                Case "Run Macro1"
                      Call Macro1
                      CommandButton1.Caption = "Run Macro2"
                Case "Run Macro2"
                      Call Macro2
                      CommandButton1.Caption = "Run Macro1"
    
          End Select
    
    End Sub
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: One Command button for 2 macros( Not in the same time)

    Hi,

    try something like this (you need to assign Sub WhichMacro to the button):
    Option Explicit
    Dim MacroOne As Boolean
    
    Sub WhichMacro()
    If MacroOne = True Then
        Call Macro1
    Else
        Call Macro2
    End If
    End Sub
    
    Sub Macro1()
    MsgBox "macro1"
    MacroOne = False
    End Sub
    
    Sub Macro2()
    MsgBox "macro2"
    MacroOne = True
    End Sub
    Last edited by RHCPgergo; 12-13-2012 at 09:08 AM. Reason: spelling

  4. #4
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: One Command button for 2 macros( Not in the same time)

    Hi Norie and RHCPgergo abd thank for you answer. Nories your solution is exactly what i want and its working really good. Specially i like that it change the text.
    RHCPgergo your is also really good, for me i just want the text changed. But great also.

    Thanks to both will mark this as solved.

    Have a nice day

    Sincerely
    Abjac

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1