3
votes

i need to click a button(FormControl) on an excel sheet and run the macro assigned to it, through VBA code.

I tried what was suggested here https://stackguides.com/questions/130166/clicking-command-button-from-other-workbook but it didn't work for me.

Is there any other way to do this ??

4
why not? What didn't work? Any errors? - rene

4 Answers

8
votes

Fairly easy method for doing this, even if it's not really documented.

CommandButton1.Value = True
3
votes

Did you actually try? Because you want exaclty what is suggested there.

Application.Run Activesheet.Shapes(1).OnAction
0
votes

If in a worksheet. I used this in the past and it worked!

Sheet1.CommandButton1_Click

else

Sheets("Sheet Name").CommandButton1_Click
0
votes

In my case, I needed to add a button, say on Sheet1, to call the code of CommandButton1 on, say, Sheet2. First I had to delete the 'Private' statement that was in front of CommandButton1_Click(). Then I had to call Worksheets("Sheet2").Activate before calling Worksheets("Sheet2").CommandButton1_Click. Then it worked. You can then add Worksheets("Sheet1").Activate to get you back to your original sheet. So:

Private Sub CommandButton1_Click()
Worksheets("Sheet2").Activate
Worksheets("Sheet2").CommandButton1_Click
Worksheets("Sheet1").Activate
End Sub