Thread: click with code
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Fank Kabel Fank Kabel is offline
external usenet poster
 
Posts: 2
Default click with code

Hi
why not call directly the code behind this button in your
events. You may put the processing code in a public sub
and call this from your other events?

-----Original Message-----
Hi,

Is there any way to click a button on a worksheet using
code.
So far I've assigned an accelerator to the button which
works if I actually do it, but not when I use SendKeys to
do it.

Here is my code. I've simplified it to highlight the
problem.
It's a sheet with 2 commandbuttons and code in the
BeforeClose event.

Private Sub Commandbutton1_Click()
if Msgbox("OK to close?", vbyesno)=vbyes then 'click yes
ThisWorkBook.Close
end if
end sub

Private Sub CommandButton2_Click()'set an accelerator
of "A"
Workbooks.Open("another workbook")
End sub

Private Sub Workbook_Beforeclose(Cancel as Boolean)
if msgbox("Do you want to open the other
workbook?",vbyesno)= vbyes then 'click yes
cancel = true
sendkeys "%A"
else
thisworkbook.saved= true
end if
exit sub



.