VBA & Macro Problems

How to Use an Excel VBA Macro to Add Static Text and a Timestamp in WPS Office

Aamir Naveed AkramAamir Naveed Akram Nov 13, 2026 869 views

Question details

The user needs a VBA macro that enters a text prefix and the current date and time into the active Excel cell as a static value.

How to Use an Excel VBA Macro to Add Static Text and a Timestamp in WPS Office
Product
WPS Office Spreadsheets (Excel-compatible)
Device & OS
not provided
Scenario
The user wants to automate inserting a fixed text prefix plus a timestamp into the selected cell without the value changing later.
Observed behavior
After the macro runs, the active cell should contain the combined text and timestamp as a static value; it should not update when the workbook recalculates.
Before you start

Make sure the Developer tab is available in WPS Office Spreadsheets so you can access the VBA editor and macro controls. Save the target workbook as a macro-enabled .xlsm file so the VBA code is retained.

Solution 1Recommended

Add the VBA Macro and Run It in the Active Cell

Use this method when you need a one-time static text prefix plus the current date and time in the selected cell.

The macro uses ActiveCell.Value instead of a worksheet formula, so the inserted text and timestamp remain static after the macro finishes.

The format string "yyyymmddhhnnss" produces a compact numeric timestamp; you can change it to another VBA Format pattern if needed.

1
Open the VBA editor

In WPS Office Spreadsheets, press Alt+F11 or click Developer > Visual Basic to open the VBA editor.

2
Insert a module

In the VBA editor, click Insert > Module to create a new code module.

3
Paste the macro code

Paste the following code into the module: Sub TextPlusTimeStamp() ActiveCell.Value = "DVC" & Format(Now, "yyyymmddhhnnss") End Sub

4
Save as a macro-enabled workbook

Click File > Save As, choose Excel Macro-Enabled Workbook (*.xlsm), and save the file.

5
Run the macro

Select the target cell, then go to Developer > Macros, choose TextPlusTimeStamp, and click Run.

Add the VBA Macro and Run It in the Active Cell
Use .xlsm to keep the macro: If you save the workbook as the default .xlsx format, the VBA macro may be removed or unavailable.

Create a Static Text and Timestamp Macro with WPS Office Spreadsheets

WPS Office Spreadsheets supports Excel VBA-style macros, so you can add and run the TextPlusTimeStamp macro directly, then save the file in .xlsm format to preserve it.

  1. 1. Open your workbook: Launch WPS Office Spreadsheets and open the workbook where you want to add the macro.
  2. 2. Open the VBA editor: Press Alt+F11 or go to Developer > Visual Basic to open the VBA editor.
  3. 3. Add the macro code: Click Insert > Module, then paste the TextPlusTimeStamp macro code into the module.
  4. 4. Save the macro-enabled file: Save the workbook as an Excel Macro-Enabled Workbook (*.xlsm).
  5. 5. Run the macro: Select the target cell and run the macro from Developer > Macros or from a button.
Run VBA-compatible macros directly in WPS Office SpreadsheetsGenerate static text and timestamp values that do not update on recalculationOpen and save Excel .xlsm macro-enabled workbooks for full format compatibilityUse the familiar ribbon and VBA editor interface with no extra costKeep your workflow lightweight with the free WPS Office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does the timestamp not update when the workbook recalculates?

Because the macro writes the current date and time to ActiveCell.Value as a static value, rather than entering a worksheet formula such as =NOW().

Can I change the "DVC" prefix or the timestamp format?

Yes. Replace "DVC" with your preferred text and change the format string "yyyymmddhhnnss" to another VBA Format pattern, such as "yyyy-mm-dd hh:mm:ss".

Why do I need to save the workbook as .xlsm?

The .xlsm format is macro-enabled. A standard .xlsx workbook cannot retain VBA macros, so saving as .xlsm keeps the code available.

How do I assign the macro to a button?

Enable the Developer tab, click Developer > Insert > Button (Form Control), draw the button, and select TextPlusTimeStamp in the Assign Macro dialog.