• Creating a timed message box with no buttons

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Creating a timed message box with no buttons

    Author
    Topic
    #465011

    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

    Viewing 11 reply threads
    Author
    Replies
    • #1192869

      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)

    • #1198481

      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!
      Computer Specs

    • #1199706

      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!
      Computer Specs

    • #1200078

      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!
      Computer Specs

    • #1200805

      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!
      Computer Specs

    • #1201724

      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!
      Computer Specs

    • #1202495

      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!
      Computer Specs

    • #1203404

      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!
      Computer Specs

    • #1204239

      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!
      Computer Specs

    • #1204756

      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

      • #1204782

        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!
        Computer Specs

        • #1204826

          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

        • #1205302

          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

          Definitely in a module and not ThisDocument. Tried ShowModal = False before posting and that didn’t work for me either.

          I’m just not seeing what’s gone wrong. Maybe it will come to me in my dreams… just what I need!

          Update: I’ve just tried this in Word 2003 and it worked as written (with ShowModal set to False). Not sure why it isn’t working in 2007, but at least I can eliminate the code.

          Further Update: Still not quite sure what happened, but my form now closes in 2007. I changed the form’s *font* from Verdana to Tahoma and now it works. Hmmmmmm. Still, nice it works, eh? I’ll review and see if I changed anything else.

          Thanks,
          Kim

    • #1205066

      Gary,

      Thanks, another trick for my bag!

      RG

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1205200

      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

    Viewing 11 reply threads
    Reply To: Creating a timed message box with no buttons

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: