Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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



  #2   Report Post  
Posted to microsoft.public.excel.programming
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



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
right-click on a control button and view code does nothing Kate Excel Worksheet Functions 11 November 16th 07 12:24 AM
option buttons run Click code when value is changed via VBA code neonangel Excel Programming 5 July 27th 04 08:32 AM
Code to tab from option button click Glen Millar Excel Programming 3 May 19th 04 02:14 AM
Trigger Code with Mouse Click Phil Hageman[_3_] Excel Programming 1 February 2nd 04 04:39 PM


All times are GMT +1. The time now is 10:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"