• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

One Macro Code which can run different macro codes

K Raghavender rao

New Member
Hi All,

Hope everyone is doing fine.

I have five macro codes, every time i need to click on each and every macro once job is done for each code...it their is any way i can have one code which will run all the codes one by one by clicking on one button.

Thanks,
K Raghavender Rao
 
Hi,

Yes.

Instead of having a set-up like this (which is what you described):
Code:
Private Sub CommandButton1_Click()
  Do1
End Sub
 
Private Sub CommandButton2_Click()
  Do2
End Sub
 
Private Sub CommandButton3_Click()
  Do3
End Sub
 
Private Sub CommandButton4_Click()
  Do4
End Sub
 
Private Sub CommandButton5_Click()
  Do5
End Sub
 
Sub Do1()
  MsgBox "Do1"
End Sub
 
Sub Do2()
  MsgBox "Do2"
End Sub
 
Sub Do3()
  MsgBox "Do3"
End Sub
 
Sub Do4()
  MsgBox "Do4"
End Sub
 
Sub Do5()
  MsgBox "Do5"
End Sub

You can have a set-up like this:

Code:
Private Sub CommandButton1_Click()
  Do1
  Do2
  Do3
  Do4
  Do5
End Sub
 
Sub Do1()
  MsgBox "Do1"
End Sub
 
Sub Do2()
  MsgBox "Do2"
End Sub
 
Sub Do3()
  MsgBox "Do3"
End Sub
 
Sub Do4()
  MsgBox "Do4"
End Sub
 
Sub Do5()
  MsgBox "Do5"
End Sub
 
That's fine too - it's the same thing as I posted. The Call keyword in VBA is optional so in my example I just wrote the macro names without the Call keyword.
 
Back
Top