How to call a button click from another Macro?

spacely

Board Regular
Joined
Oct 26, 2007
Messages
248
Hello,

There is a button click private sub on another sheet, I just want to invoke it from a macro. The below doesn't work:

CallByName Sheet30, CommandButton10_Click, VbMethod


Is there a better approach?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I would assume he means he has a ActiveX Command button in one sheet with a script.
And wants to call that script from a ActiveX Command Button in another sheet.

ActiveX Command Button scripts normally look like This:
Code:
Private Sub CommandButton1_Click()
MsgBox "Hello"
End Sub

I do not have the answer.



Hello,

have you tried to make Public ...?
 
Last edited:
Upvote 0
Now if I'm correct and you have Two ActiveX command buttons on two different sheets.

First Remove the part that says Private

Then you could call the script from another ActiveX control by using something like this.

Code:
Private Sub CommandButton1_Click()
'This command Button is in sheet(1)
'Modified  4/14/2019  7:45:32 AM  EDT
Call Sheets(2).CommandButton1_Click
End Sub
 
Upvote 0
I am trying to call

Private Sub CommandButton10_Click()

from a macro, not another button.

I removed the Private, and used from within my Macro:

Call Sheets(30).CommandButton10_Click

but got

Object doesn't support this property or method.

Is there a different way to invoke?
 
Last edited:
Upvote 0
Move the code from CommandButton10_Click into SomeSub in a normal module.
CommandButton10_Click should now read

Code:
Private Sub CommandButton10_Click()
    Call SomeSub
End Sub

And you can call SomeSub from anywhere.
 
Upvote 0
Now it's not finding other functions within the new SomeSub.

I also put the SomeSub at the bottom of the Sheet Code, but then the SomeSub itself was not found.

What if I take all Privates off from everything? Will everything be found and nothing broken?
 
Last edited:
Upvote 0
You can have Option Private Module and remove Private from the one routine you need to call ...

HTH
 
Upvote 0
Not helping :(

I even put a Public in front of the Command10 button's click code. No luck fincing it.

Do I need to bring ALL code into some new Module so it talks to each other?
 
Upvote 0
Ha! This worked, wiyhout removing Private or any other changes:

Worksheets("LDD Files").CommandButton10.Value = True

Weird.
 
Upvote 0

Forum statistics

Threads
1,214,845
Messages
6,121,902
Members
449,053
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top