user101
user101

Reputation: 1

Two macros on one button

Is it possible to assign two macros to one button?

Upvotes: 0

Views: 24152

Answers (3)

You mean, like this?

Private Sub CommandButton1_Click()
    Macro1
    Macro2
End Sub

Upvotes: 5

jonsca
jonsca

Reputation: 10381

If you want both macros to run at the same time, that's probably not possible. If you want to run one right after the other, simply call the second macro at the end of the first, or as Issun has pointed out, write a wrapper that calls both, and have the button call the wrapper.

Upvotes: 1

Gaijinhunter
Gaijinhunter

Reputation: 14685

If you want both to run, write a wrapper function that calls them both and just call that.

I wouldn't hard code the call to the second macro at the end of the first since it violates single responsibility plus you might need to use just the first macro in some situations.

Upvotes: 2

Related Questions