ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   calling/running a macro on another worksheet (https://www.excelbanter.com/excel-programming/387119-calling-running-macro-another-worksheet.html)

Sunny

calling/running a macro on another worksheet
 
Lets say I have a CommandButton (call it Button1) on Sheet1 that does some
calculations using cells on Sheet1 and Sheet2

On Sheet2 I have another CommandButton (call it Button2) that alters some of
the cells that are used when Button1 is clicked.

I would like to add a macro to Sheet2 so that I could run the
"CommandButton_Click()" macro on Sheet1. What would be the syntax for doing
this?

Thanks.


Norman Jones

calling/running a macro on another worksheet
 
Hi Sunny,

Try something like:

'=============
Public Sub Tester()
Dim SH As Worksheet
Dim oleObj As OLEObject

Set SH = ThisWorkbook.Sheets("Sheet1")
Set oleObj = SH.OLEObjects("CommandButton1")
oleObj.Object.Value = True
End Sub
'<<=============


---
Regards,
Norman



"Sunny" wrote in message
...
Lets say I have a CommandButton (call it Button1) on Sheet1 that does some
calculations using cells on Sheet1 and Sheet2

On Sheet2 I have another CommandButton (call it Button2) that alters some
of
the cells that are used when Button1 is clicked.

I would like to add a macro to Sheet2 so that I could run the
"CommandButton_Click()" macro on Sheet1. What would be the syntax for
doing
this?

Thanks.




Sunny

calling/running a macro on another worksheet
 
Thanks for the help, Norman. Does exactly what I needed it to.

"Norman Jones" wrote:

Hi Sunny,

Try something like:

'=============
Public Sub Tester()
Dim SH As Worksheet
Dim oleObj As OLEObject

Set SH = ThisWorkbook.Sheets("Sheet1")
Set oleObj = SH.OLEObjects("CommandButton1")
oleObj.Object.Value = True
End Sub
'<<=============


---
Regards,
Norman



"Sunny" wrote in message
...
Lets say I have a CommandButton (call it Button1) on Sheet1 that does some
calculations using cells on Sheet1 and Sheet2

On Sheet2 I have another CommandButton (call it Button2) that alters some
of
the cells that are used when Button1 is clicked.

I would like to add a macro to Sheet2 so that I could run the
"CommandButton_Click()" macro on Sheet1. What would be the syntax for
doing
this?

Thanks.






All times are GMT +1. The time now is 01:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com