Skip to main content

How to create a message box timer to auto close the message box after certain time in Excel?

When using Excel workbook, you may often use VBA scripts to solve problems. And there will be some message boxes popping up during the script running. In some cases, you will want some specified message boxes to close automatically after a certain time, instead of closing it manually. In this article, we will show you method of creating a message box timer to auto close the message box after certain time in Excel.

Create a message box timer to auto dismiss message box after certain time


Create a message box timer to auto dismiss message box after certain time

Here provides a VBA script template for you to create a message box timer.

Supposing you are running VBA script to move rows based on cell value. After finishing moving, you need a message box to pop up to tell you that the operation was successful and this message box needs to close automatically after 4 seconds (see below screenshot). Please follow the steps below.

1. Open the Microsoft Visual Basic for Applications window, click Insert > Module, and then insert the VBA code that you want to use to move rows based on cell value.

2. Copy the following VBA code 1 and put it before the code you want to operate. See screenshot below:

VBA code 1:

Private Declare PtrSafe Function CustomTimeOffMsgBox Lib "user32" Alias "MessageBoxTimeoutA" ( _
            ByVal xHwnd As LongPtr, _
            ByVal xText As String, _
            ByVal xCaption As String, _
            ByVal xMsgBoxStyle As VbMsgBoxStyle, _
            ByVal xwlange As Long, _
            ByVal xTimeOut As Long) _
    As Long

3. Copy the VBA code 2 below and put it before the line "End Sub" of the code you want to operate.

VBA code 2:

 Call CustomTimeOffMsgBox(0, "Moved successfully. This message box will be closed after 4 seconds", "Kutools for Excel", vbInformation, 0, 4000)

Note: You can change the content of the message box, and the display time of the dialog box according to your needs.

4. After running the code to perform the operation, a message box will pop up and then close automatically after certian time (in this case is 4 seconds).


Related articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions…
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Ufff... great!!... very good... thank you
This comment was minimized by the moderator on the site
Ufff... buenisimo!!... muy bien... gracias
This comment was minimized by the moderator on the site
Hi. Thanks for this - it's really useful. Is there any way to stop Excel (VBA) chiming when the box appears? I need to use this as a repeatedly looping message in a piece of code but aside from turning the volume down I don't know how to stop the warning sound appearing everytime the box appears? Thanks.
This comment was minimized by the moderator on the site
Hi thebankman,This is the default application system sounds in windows. You can turn it off as shown in the screenshot below.
This comment was minimized by the moderator on the site
Thanks Crystal. Much appreciated
This comment was minimized by the moderator on the site
Hi. is there any way to stop Excel (VBA) chiming when the box appears? I need to use this as a repeatedly looping message in a piece of code but aside from turning the volume down I don't know how to stop the warning sound appearing everytime the box appears? Thanks.
This comment was minimized by the moderator on the site
It is really nice, but on my codes I'm using the "GetAsyncKeyState" function to recognize the entry status for my data (using an scan gun) and the "MsgBoxTimeout" function is affecting the "GetAsyncKeyState" function. Without the "MsgBoxTimeOut" everything is working normal, when I include it, is like disactivate the "GetAsyncKeyState" function, but both not want to work together. Have you any suggestion?
This comment was minimized by the moderator on the site
You are just perfect... :lol: :lol: :lol: 8) 8) 8)
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations