VBA & Macro Problems

Enter the Current Time with Seconds in Excel Using a VBA Macro

Chanuka GeekiyanageChanuka Geekiyanage Nov 12, 2026 869 views

Question details

The user needs a reliable way to enter the current time, including seconds, as a fixed value in an Excel cell.

Enter the Current Time with Seconds in Excel Using a VBA Macro
Product
Microsoft Excel
Device & OS
not provided
Scenario
The user wants to quickly timestamp the active cell with the current time and display it in hh:mm:ss format.
Observed behavior
Excel does not provide a standard built-in keyboard shortcut that reliably inserts and displays the current time with seconds.
Before you start

To use the macro method, open the workbook in a desktop version of Excel that supports VBA and save the file as an Excel Macro-Enabled Workbook (*.xlsm). Make sure macros are enabled when you reopen the workbook.

Solution 1Recommended

Create a VBA macro to insert the current time with seconds

Use this method when you need a permanent time value with seconds in the selected cell and want to trigger it from a shortcut or toolbar button.

The macro writes the current system time to the active cell and applies a time format that always shows hours, minutes, and seconds. Unlike a NOW-based formula, the inserted value does not recalculate later.

1
Open the Visual Basic Editor

In Excel, press Alt+F11 to open the Visual Basic Editor. In the Project pane, select your workbook, then choose Insert > Module.

2
Add the timestamp macro

Paste this code into the new module: Sub EnterCurrentTimeWithSeconds() ActiveCell.Value = Time ActiveCell.NumberFormat = "hh:mm:ss" End Sub

3
Run the macro in the active cell

Return to the worksheet, select the target cell, then press Alt+F8. Select EnterCurrentTimeWithSeconds and click Run.

4
Assign a keyboard shortcut

Press Alt+F8, select EnterCurrentTimeWithSeconds, click Options, enter a shortcut key, and click OK. Select a cell and use that shortcut whenever you need a timestamp.

5
Save the workbook as macro-enabled

Choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) so the VBA code and shortcut remain available.

Create a VBA macro to insert the current time with seconds
Fixed timestamp created: Each time you run the macro, Excel enters a fixed time value in the active cell and displays seconds using the hh:mm:ss format.
Work efficiently with WPS Office

Insert Fixed Timestamps with Seconds in WPS Spreadsheets

WPS Spreadsheets provides a familiar worksheet environment for entering and formatting timestamps. In versions with VBA macro support, you can add a macro that writes the current time to the selected cell, formats it as hh:mm:ss, and runs from the Macro dialog or an assigned shortcut.

  1. 1. Open the workbook in WPS Spreadsheets: Launch WPS Office, open the workbook, and select the worksheet where you want to insert time values.
  2. 2. Access the VBA editor: Open the Developer tab and select Visual Basic, then choose Insert > Module in the VBA editor.
  3. 3. Add the timestamp code: Paste a macro that assigns Time to ActiveCell.Value and sets ActiveCell.NumberFormat to "hh:mm:ss".
  4. 4. Run or assign the macro: Return to WPS Spreadsheets, select a target cell, and use Developer > Macros to run the macro or assign it a shortcut where available.
  5. 5. Save as a macro-enabled file: Use Save As and select the Excel Macro-Enabled Workbook (*.xlsm) format to retain the macro.
Create fixed current-time entries with a VBA macro and the hh:mm:ss number format.Format time cells through Format Cells without changing the stored value.Open and edit Microsoft Excel .xlsx and macro-enabled .xlsm workbooks with compatible formatting.Use a lightweight, familiar spreadsheet interface for Excel-style calculations and data entry.
microsoft office alternative - wps office

Frequently Asked Questions

How do I insert the current time with seconds as a fixed value in Excel?

Use a VBA macro that sets ActiveCell.Value = Time and ActiveCell.NumberFormat = "hh:mm:ss". Running the macro inserts a non-recalculating time value in the selected cell.

Why does Ctrl+Shift+; not show seconds in my Excel timestamp?

The cell may be using a time format that hides seconds. Select the cell, press Ctrl+1, choose Custom, and apply the format hh:mm:ss.

Can I use NOW() to create a permanent timestamp?

No. NOW() recalculates when Excel recalculates. Use a VBA macro or copy and paste the formula result as values if the timestamp must remain unchanged.

How can I insert both the current date and time with seconds?

In the macro, replace Time with Now, then apply a format such as yyyy-mm-dd hh:mm:ss. This writes the current date and time as a fixed value.

Why must I save the workbook as an .xlsm file?

An .xlsm file preserves VBA code. If you save a macro workbook as .xlsx, Excel removes the macro from the file.