Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Star Lounger
    Join Date
    May 2009
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've found lots of code for creating message boxes. I can't find code for a simple one that displays for 1 or 2 seconds alerting the user to a short message. I don't want the user to have to click a button to close the message box.

    Sub DateMsg()
    MsgBox "Format date mmmm/dd/yyyy."
    End Sub

    Thank you!
    Charlie
    charlie6067

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can't use a MsgBox for that purpose. You'll have to create a small userform in the Visual Basic Editor, with a label whose caption is the message you want to display.

    You can then show the userform and unload it after a specified time, using for example

    Application.OnTime DateAdd("s", 2, Now), "MacroThatUnloadsForm"

    (This is for Word and Excel)

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    I had a little trouble getting this to work...of course it was because I put the message display BEFORE the timer...duh!

    Here's my example code:

    Code:
    Sub Testit()
    
      ufMessageBoard.lblMessage.Caption = "Testing timed message"
      
      'Application.OnTime Now + TimeValue("00:00:03"), "UnloadMessageBoard"  'This works also
      Application.OnTime DateAdd("s", 3, Now), "UnloadMessageBoard"
      
      ufMessageBoard.Show
      
    End Sub
    
    Sub UnloadMessageBoard()
    
       ufMessageBoard.Hide
       
    End Sub
    ufMessageBoard is just an Excel form with a single label field.
    I used a label field because it won't appear like a text field
    which may be inviting the user to enter something.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    I had a little trouble getting this to work...of course it was because I put the message display BEFORE the timer...duh!

    Here's my example code:

    Code:
    Sub Testit()
    
      ufMessageBoard.lblMessage.Caption = "Testing timed message"
      
      'Application.OnTime Now + TimeValue("00:00:03"), "UnloadMessageBoard"  'This works also
      Application.OnTime DateAdd("s", 3, Now), "UnloadMessageBoard"
      
      ufMessageBoard.Show
      
    End Sub
    
    Sub UnloadMessageBoard()
    
       ufMessageBoard.Hide
       
    End Sub
    ufMessageBoard is just an Excel form with a single label field.
    I used a label field because it won't appear like a text field
    which may be inviting the user to enter something.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    I had a little trouble getting this to work...of course it was because I put the message display BEFORE the timer...duh!

    Here's my example code:

    Code:
    Sub Testit()
    
      ufMessageBoard.lblMessage.Caption = "Testing timed message"
      
      'Application.OnTime Now + TimeValue("00:00:03"), "UnloadMessageBoard"  'This works also
      Application.OnTime DateAdd("s", 3, Now), "UnloadMessageBoard"
      
      ufMessageBoard.Show
      
    End Sub
    
    Sub UnloadMessageBoard()
    
       ufMessageBoard.Hide
       
    End Sub
    ufMessageBoard is just an Excel form with a single label field.
    I used a label field because it won't appear like a text field
    which may be inviting the user to enter something.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    I had a little trouble getting this to work...of course it was because I put the message display BEFORE the timer...duh!

    Here's my example code:

    Code:
    Sub Testit()
    
      ufMessageBoard.lblMessage.Caption = "Testing timed message"
      
      'Application.OnTime Now + TimeValue("00:00:03"), "UnloadMessageBoard"  'This works also
      Application.OnTime DateAdd("s", 3, Now), "UnloadMessageBoard"
      
      ufMessageBoard.Show
      
    End Sub
    
    Sub UnloadMessageBoard()
    
       ufMessageBoard.Hide
       
    End Sub
    ufMessageBoard is just an Excel form with a single label field.
    I used a label field because it won't appear like a text field
    which may be inviting the user to enter something.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  7. #7
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    I had a little trouble getting this to work...of course it was because I put the message display BEFORE the timer...duh!

    Here's my example code:

    Code:
    Sub Testit()
    
      ufMessageBoard.lblMessage.Caption = "Testing timed message"
      
      'Application.OnTime Now + TimeValue("00:00:03"), "UnloadMessageBoard"  'This works also
      Application.OnTime DateAdd("s", 3, Now), "UnloadMessageBoard"
      
      ufMessageBoard.Show
      
    End Sub
    
    Sub UnloadMessageBoard()
    
       ufMessageBoard.Hide
       
    End Sub
    ufMessageBoard is just an Excel form with a single label field.
    I used a label field because it won't appear like a text field
    which may be inviting the user to enter something.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  8. #8
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    I had a little trouble getting this to work...of course it was because I put the message display BEFORE the timer...duh!

    Here's my example code:

    Code:
    Sub Testit()
    
      ufMessageBoard.lblMessage.Caption = "Testing timed message"
      
      'Application.OnTime Now + TimeValue("00:00:03"), "UnloadMessageBoard"  'This works also
      Application.OnTime DateAdd("s", 3, Now), "UnloadMessageBoard"
      
      ufMessageBoard.Show
      
    End Sub
    
    Sub UnloadMessageBoard()
    
       ufMessageBoard.Hide
       
    End Sub
    ufMessageBoard is just an Excel form with a single label field.
    I used a label field because it won't appear like a text field
    which may be inviting the user to enter something.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  9. #9
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    I had a little trouble getting this to work...of course it was because I put the message display BEFORE the timer...duh!

    Here's my example code:

    Code:
    Sub Testit()
    
      ufMessageBoard.lblMessage.Caption = "Testing timed message"
      
      'Application.OnTime Now + TimeValue("00:00:03"), "UnloadMessageBoard"  'This works also
      Application.OnTime DateAdd("s", 3, Now), "UnloadMessageBoard"
      
      ufMessageBoard.Show
      
    End Sub
    
    Sub UnloadMessageBoard()
    
       ufMessageBoard.Hide
       
    End Sub
    ufMessageBoard is just an Excel form with a single label field.
    I used a label field because it won't appear like a text field
    which may be inviting the user to enter something.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  10. #10
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    I had a little trouble getting this to work...of course it was because I put the message display BEFORE the timer...duh!

    Here's my example code:

    Code:
    Sub Testit()
    
      ufMessageBoard.lblMessage.Caption = "Testing timed message"
      
      'Application.OnTime Now + TimeValue("00:00:03"), "UnloadMessageBoard"  'This works also
      Application.OnTime DateAdd("s", 3, Now), "UnloadMessageBoard"
      
      ufMessageBoard.Show
      
    End Sub
    
    Sub UnloadMessageBoard()
    
       ufMessageBoard.Hide
       
    End Sub
    ufMessageBoard is just an Excel form with a single label field.
    I used a label field because it won't appear like a text field
    which may be inviting the user to enter something.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  11. #11
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts
    This seems like such a handy thing that I tried it in Word 2007 and I cannot get it to work. I changed names slightly, checked program Help which suggested including the full path to the macro, used the When and Name labels, did not include the lblMessage.Caption to make it simpler. No error message. The form displays and never closes.

    Code:
    Sub TestTimedMessage()
      Application.OnTime When:=Now + TimeValue("00:00:05"), Name:="Normal.TestMacros.UnloadTimedDialog"
      frmTimedDialog.Show
    End Sub
    
    Sub UnloadTimedDialog()
      frmTimedDialog.Hide
    End Sub
    What am I missing? Security is wide open.
    Thanks, Kim

  12. #12
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quote Originally Posted by kmurdock View Post
    This seems like such a handy thing that I tried it in Word 2007 and I cannot get it to work. I changed names slightly, checked program Help which suggested including the full path to the macro, used the When and Name labels, did not include the lblMessage.Caption to make it simpler. No error message. The form displays and never closes.

    Code:
    Sub TestTimedMessage()
      Application.OnTime When:=Now + TimeValue("00:00:05"), Name:="Normal.TestMacros.UnloadTimedDialog"
      frmTimedDialog.Show
    End Sub
    
    Sub UnloadTimedDialog()
      frmTimedDialog.Hide
    End Sub
    What am I missing? Security is wide open.
    Thanks, Kim
    I tried it in Word and also ran into problems.
    1. Make sure it's in a module not ThisDocument
    2. Change the form's behavior to ShowModal = False (this makes it work!)

    I looked for the ShowModal property in the Object browser but could not find it so
    you'll have to set it when you design the form vs at runtime.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  13. #13
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Quote Originally Posted by RetiredGeek View Post
    I looked for the ShowModal property in the Object browser but could not find it so
    you'll have to set it when you design the form vs at runtime.
    RG
    RG,

    You can set the form's modal property at runtime - use either of these two constants:

    frmTimedDialog.Show vbModal
    or
    frmTimedDialog.Show vbModeless

    They can be found in the Object Browser by searching on "Modal".

    Gary

  14. #14
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Gary,

    Thanks, another trick for my bag!

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  15. #15
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    NJ, USA
    Posts
    239
    Thanks
    2
    Thanked 1 Time in 1 Post
    I think using Application.Wait would be simpler(?). For example:

    Sub Testit()
    Dim frmMessage As FMessage

    Set frmMessage = New FMessage

    Load frmMessage
    frmMessage.Caption = "Testing timed message"

    frmMessage.Show vbModeless

    Beep
    Application.Wait (Now + TimeValue("0:00:03"))

    Unload frmMessage
    End Sub

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •