Note: The other languages of the website are Google-translated. Back to English

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:


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom
Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
You are just perfect... :lol: :lol: :lol: 8) 8) 8)
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
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
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
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations