Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Display and close form automatically

Here's some code I'm working on. I want to display a message to the
user for approximately 3 seconds and then continue on with the code.
I've built a form with a message written on it. When i run this code
the form displays and then it doesn't do anything. The Sleep
function works fine.........I just don't know how to get the form to
close automatically.



On Error Resume Next

Shell BankNamePath, vbMaximizedFocus

If Err.Number = 5 Or Err.Number = 53 Then

UserForm1.Show
Sleep 3000
Unload UserForm1

Call OpenDefaultDiscTray
Sleep 5000
Call CloseDefaultDiscTray

Shell BankNamePath, vbMaximizedFocus

End If

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Display and close form automatically

try:
Application.Wait Now + TimeValue("00:00:03")
Unload UserForm1

Billy Rogers wrote:
Here's some code I'm working on. I want to display a message to the
user for approximately 3 seconds and then continue on with the code.
I've built a form with a message written on it. When i run this code
the form displays and then it doesn't do anything. The Sleep
function works fine.........I just don't know how to get the form to
close automatically.



On Error Resume Next

Shell BankNamePath, vbMaximizedFocus

If Err.Number = 5 Or Err.Number = 53 Then

UserForm1.Show
Sleep 3000
Unload UserForm1

Call OpenDefaultDiscTray
Sleep 5000
Call CloseDefaultDiscTray

Shell BankNamePath, vbMaximizedFocus

End If


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Display and close form automatically

The problem is that you are displaying the form "modally". When you do this,
on the line of code

UserForm1.Show

code execution pauses at that line until the form is hidden (of course, code
within UserForm1 can still run). Only after the form is hidden or unloaded
will the code continue execution at the next line after the Show method. In
Excel 2000 and later, you can display the form "modelessly", in which case
the form is shown an execution continues while the form is displayed.

UserForm1.Show vbModeless


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Billy Rogers" wrote in message
ups.com...
Here's some code I'm working on. I want to display a message to the
user for approximately 3 seconds and then continue on with the code.
I've built a form with a message written on it. When i run this code
the form displays and then it doesn't do anything. The Sleep
function works fine.........I just don't know how to get the form to
close automatically.



On Error Resume Next

Shell BankNamePath, vbMaximizedFocus

If Err.Number = 5 Or Err.Number = 53 Then

UserForm1.Show
Sleep 3000
Unload UserForm1

Call OpenDefaultDiscTray
Sleep 5000
Call CloseDefaultDiscTray

Shell BankNamePath, vbMaximizedFocus

End If


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Display and close form automatically

Chips answer is spot on. That being said the other way to make the form
disappear after a short period of time is to place the code into the forms
Activate event, something like this (th eform does not need to be shown
modeless)...

Private Sub UserForm_Activate()
Application.Wait Now + TimeSerial(0, 0, 3)
Me.Hide
End Sub

The benefit to this is if you intend to use this same form in multiple
places then you do not need to keep on re-writing the same code. If you don't
intend to re-use this form then there is absolutely no benefit.
--
HTH...

Jim Thomlinson


"Chip Pearson" wrote:

The problem is that you are displaying the form "modally". When you do this,
on the line of code

UserForm1.Show

code execution pauses at that line until the form is hidden (of course, code
within UserForm1 can still run). Only after the form is hidden or unloaded
will the code continue execution at the next line after the Show method. In
Excel 2000 and later, you can display the form "modelessly", in which case
the form is shown an execution continues while the form is displayed.

UserForm1.Show vbModeless


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Billy Rogers" wrote in message
ups.com...
Here's some code I'm working on. I want to display a message to the
user for approximately 3 seconds and then continue on with the code.
I've built a form with a message written on it. When i run this code
the form displays and then it doesn't do anything. The Sleep
function works fine.........I just don't know how to get the form to
close automatically.



On Error Resume Next

Shell BankNamePath, vbMaximizedFocus

If Err.Number = 5 Or Err.Number = 53 Then

UserForm1.Show
Sleep 3000
Unload UserForm1

Call OpenDefaultDiscTray
Sleep 5000
Call CloseDefaultDiscTray

Shell BankNamePath, vbMaximizedFocus

End If



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
How do you automatically display a vba form in excel 2007 Kathryn Excel Discussion (Misc queries) 1 April 21st 10 04:51 PM
Close form automatically upon opening workbook Ixtreme Excel Discussion (Misc queries) 2 September 18th 09 02:56 PM
automatically close form before closing Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 0 September 19th 08 08:26 PM
Is it possible to have a messageBox to display for 2 sec's and then Close AUTOMATICALLY ? Corey Excel Programming 3 February 26th 07 01:18 AM
In Excel how can a number automatically display in text form Curtis A Excel Worksheet Functions 2 February 26th 05 11:31 AM


All times are GMT +1. The time now is 09:42 AM.

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"