View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Launch Click Event Using Application.Run

You know the codename of that sheet that holds that button, right?

Dim OtherWkbk As Workbook
Set OtherWkbk = Workbooks("Budget Payee Names.xls")
Application.Run "'" & OtherWkbk.Name & "'!sheet1.cbAddPayee_Click"

Replace sheet1 with the codename for worksheet that owns that commandbutton.

Another way if you know the sheetname, but not its codename:

Dim OtherWkbk As Workbook
Set OtherWkbk = Workbooks("Budget Payee Names.xls")
OtherWkbk.Worksheets("Sheetnamehere").cbAddPayee.V alue = True



cellist wrote:

I want to launch the code that handles a
Click Event procedure defined in one
workbook from another workbook. The
Click Event handler is defined in
workbook "Budget Payee Names.xls" and is
named cbAddPayee_Click.

Private Sub cbAddPayee_Click()
MsgBox "entered cbAddPayee_Click"
End Sub

When I run the following code in the
"other" workbook I get error 1004.

Sub launchAddPayee()
Application.Run "'Budget Payee Names.xls'" & _
"!cbAddPayee_Click"
End Sub

Run-time error '1004':
The macro "Budget Payee Names.xls
'!cbAddPayee_Click' cannot be found.

I think I've ruled out the usual suspects -- syntax error, subroutine name
typo. I've also tried the code with and without the "Private" on the click
event sub. Does the target of application.run need to be in a module, as
opposed to code that resides within the "sheet"?

Any help will be appreciated,

Phil


--

Dave Peterson