Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How to activate command button on form by macro

I'm working on a macro to load, fill out, and run a form. I think I
know how to do everything except run the form. By run the form I mean
"click" the OK command button.

Here's basically what I have (in the same workbook as the form):

Load MyForm
MyForm.textbox = "some text"
MyForm.OKbutton.SetFocus
Application.SendKeys "{ENTER}"

I thought I could set the focus to the OK command button and send the
ENTER key but that isn't working. Should this work or is there some
other way to click the OK command button?

Denis
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How to activate command button on form by macro

By default when you created the OKbutton the click event procedure will be
private so it will look something like...

Private OKbutton_Click()

This means the the procedure is not exposed outside of the form. To expose
it you just need to change it to Public

Public OKbutton_Click()

Now you can call it like this...
call MyForm.OKbutton_Click()

You do not need to load the form. In fact that will halt the execution
waiting for user input on the form.
--
HTH...

Jim Thomlinson


"Denis" wrote:

I'm working on a macro to load, fill out, and run a form. I think I
know how to do everything except run the form. By run the form I mean
"click" the OK command button.

Here's basically what I have (in the same workbook as the form):

Load MyForm
MyForm.textbox = "some text"
MyForm.OKbutton.SetFocus
Application.SendKeys "{ENTER}"

I thought I could set the focus to the OK command button and send the
ENTER key but that isn't working. Should this work or is there some
other way to click the OK command button?

Denis

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How to activate command button on form by macro

On Oct 24, 1:09 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
By default when you created the OKbutton the click event procedure will be
private so it will look something like...

Private OKbutton_Click()

This means the the procedure is not exposed outside of the form. To expose
it you just need to change it to Public

Public OKbutton_Click()

Now you can call it like this...
call MyForm.OKbutton_Click()

You do not need to load the form. In fact that will halt the execution
waiting for user input on the form.
--
HTH...

Jim Thomlinson


Thanks. I wondered if that was the right approach or if there was a
better or right way to do this.

Denis


"Denis" wrote:
I'm working on a macro to load, fill out, and run a form. I think I
know how to do everything except run the form. By run the form I mean
"click" the OK command button.


Here's basically what I have (in the same workbook as the form):


Load MyForm
MyForm.textbox = "some text"
MyForm.OKbutton.SetFocus
Application.SendKeys "{ENTER}"


I thought I could set the focus to the OK command button and send the
ENTER key but that isn't working. Should this work or is there some
other way to click the OK command button?


Denis


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
macro attached to command button - VBA form Roy Gudgeon[_2_] Excel Discussion (Misc queries) 2 March 16th 10 12:44 PM
Accessing the text of a form command button from underlying macro Chrisso Excel Programming 6 September 15th 07 03:02 PM
Command Button vs Form Button Bri[_3_] Excel Programming 2 February 3rd 06 08:18 AM
Macro to activate form button kkknie[_90_] Excel Programming 1 May 11th 04 08:31 PM
using 'enter' on a textbox to activate a command button? neowok[_23_] Excel Programming 1 February 25th 04 12:25 PM


All times are GMT +1. The time now is 11:42 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"