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

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