ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   activating a command button (https://www.excelbanter.com/excel-discussion-misc-queries/242192-activating-command-button.html)

Chuck

activating a command button
 
I have a command button on sheet1 named george.
i want it to activate/run a command button on sheet2 named harry.
can i do this?
how?

Dave Peterson

activating a command button
 
You have at least a couple of choices.

This is the code I used under the Sheet2 module.
Option Explicit
Sub George_Click()
MsgBox "hi from George"
End Sub

Notice that the Private keyword is gone. That's so the "Call" can find the
procedure.

This is the code under the Sheet1 module:
Option Explicit
Private Sub Harry_Click()
Call Sheet2.George_Click
End Sub

=========
Another way:
Under Sheet2:
Option Explicit
Private Sub George_Click()
MsgBox "hi from George"
End Sub

Notice that the Private keyword is back.

And under Sheet1:
Option Explicit
Private Sub Harry_Click()
Application.Run "Sheet2.George_Click"
End Sub

(in both of these cases, that Sheet2 is the code name for the sheet--not the
name you see in excel on the sheet tab.)

=======
And one more way:
Under Sheet2:
Option Explicit
Private Sub George_Click()
MsgBox "hi from George"
End Sub

Under Sheet1:
Option Explicit
Private Sub Harry_Click()
Worksheets("Sheet2").OLEObjects("George").Object.V alue = True
End Sub




chuck wrote:

I have a command button on sheet1 named george.
i want it to activate/run a command button on sheet2 named harry.
can i do this?
how?


--

Dave Peterson


All times are GMT +1. The time now is 09:54 PM.

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