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:
- How to pop up message box when clicking on a certain cell in Excel?
- How to copy text from message box in Excel?
- How to pop up a message box upon activating/opening a specified worksheet in Excel?
- How to pop up message box to display range of cells or cell values in Excel?
- How to pop up message box if cell value changes within a range in Excel?
Best Office Productivity Tools
Easy to Uninstall Completely | Supports Office/Excel 2007-2021 and 365 | Full-Featured 30-Day Free Trial | Available in 44 Languages
Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need Is Just A Click Away...
Supercharge Your Spreadsheets: Experience Efficiency Like Never Before with Kutools for Excel
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!






