How To Execute Command/Sub-Procedure Using VBA Timer in Excel?
Tags: toexecutecommandsubp, vbamacros
Published: 2021-10-07 12:08:44

---
title: How To Execute Command/Sub-Procedure Using VBA Timer in Excel?
published: true
date: 2021-10-06 09:57:48 UTC
tags: ToExecuteCommandSubP,VBAMacros
canonical_url: https://geekexcel.com/how-to-execute-command-sub-procedure-using-vba-timer-in-excel/
---

In this blog post, we are going to see how to  **execute command/sub-procedure using a VBA timer** in Microsoft Excel. Let’s get into this article!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, you need to  **create a sample data**  with  **Start Timer button**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Sample-data-14.png)<figcaption>Sample data</figcaption>

- In the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Option Explicit
Sub TimerMsg()
'Declaring Date variable
Dim AlertTime As Date
'Displaying message box at the start of the timer
MsgBox "The alarm will go off in 3 seconds!"
'Setting timer time for 3 seconds after the activation time
AlertTime = Now + TimeValue("00:00:03")
'Activating the timer and running the MsgProcedure at the end of the timer
Application.OnTime AlertTime, "MsgProcedure"
End Sub
Sub MsgProcedure()
'Sample procedure created for timer example
MsgBox "Three Seconds is up!"
End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Save-the-Code-14.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Then, you need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/10/Run-the-Code-14.png)<figcaption>Run the Code</figcaption>

- After that, on **running the macro** , **“TimerMsg” macro** will display a **message box**.

![](https://geekexcel.com/wp-content/uploads/2021/10/TimeMsg-Macro.png)<figcaption>TimerMsg Macro</figcaption>

- Finally, when a user clicks on the **OK button** , three seconds later, **“MsgProcedure” macro** will be called. “MsgProcedure” macro will display a **message box**.

![](https://geekexcel.com/wp-content/uploads/2021/10/MsgProcedure.png)<figcaption>MsgProcedure Macro</figcaption>

## Verdict

In the above article, you can learn the simple steps ** ** on how to  **execute command/sub-procedure using a VBA timer** in Microsoft Excel. Kindly, share your  **feedback**  in the below comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!

**Read Next:**

- **[How to Transfer Specific Data from One Sheet to another through VBA in Excel?](https://geekexcel.com/how-to-transfer-specific-data-from-one-sheet-to-another-through-vba-in-excel/)**
- **[How to Copy a Range of Cells in Microsoft Excel 365?](https://geekexcel.com/how-to-copy-a-range-of-cells-in-microsoft-excel-365/)**
- **[Copy a Cell Formatting from One Cell to Other Cells in Excel 365?](https://geekexcel.com/how-to-copy-a-cell-formatting-from-one-cell-to-other-cells-in-excel-365/)**
- **[How to Copy a Formula in Excel Office 365 ~ Simple Guide!!](https://geekexcel.com/how-to-copy-a-formula-in-excel/)**