Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
right-click on a control button and view code does nothing | Excel Worksheet Functions | |||
option buttons run Click code when value is changed via VBA code | Excel Programming | |||
Code to tab from option button click | Excel Programming | |||
Trigger Code with Mouse Click | Excel Programming |