click button on userform after certain time

birdman

Board Regular
Joined
Oct 11, 2005
Messages
187
does anyone know the code to click a commandbutton that is on a userform lets say 10 seconds after that userform is opened if the user does not take any action??
 

Some videos you may like

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
birdman,
You could setup a ontime command in the form_initialize, that would execute the same code as the button after your 10 second time delay.

HTH
Cal

PS-There are also custom controls available with this functionality.
 

birdman

Board Regular
Joined
Oct 11, 2005
Messages
187
ok so it has to be done in userform_initialize. if possible, can you provide an example on how the code would look because i am not familiar with the ontime command.
 

birdman

Board Regular
Joined
Oct 11, 2005
Messages
187
i am guessing something like this but i dont know how to call the commandbutton.
Code:
Application.OnTime Now + TimeValue("00:00:10")
does anyone know how to call the commandbutton to be clicked and run?
 

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
birdman,
I would not call the button_click event, I would have the button_click event and your ontime code, call the same macro.

Ex

sub Commandbutton_1_Click()'This is not the actual event, just for display!!!
Application.OnTime Now + TimeValue("00:00:10") 'I've never used the ontime, so I'm not sure of the structure. I do know there is lots of help about it on this board.
ExecuteCode
End Sub

Sub UserForm1_initialize()'Again, not the real event call, just an example
ExecuteCode
End Sub

Sub ExecuteCode()
'Your Code Here
End sub

HTH
Cal
 

Watch MrExcel Video

Forum statistics

Threads
1,118,290
Messages
5,571,327
Members
412,382
Latest member
Langtn02
Top