How to Use an Excel VBA Macro to Add Static Text and a Timestamp in WPS Office
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.

- 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.
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.
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.
In WPS Office Spreadsheets, press Alt+F11 or click Developer > Visual Basic to open the VBA editor.
In the VBA editor, click Insert > Module to create a new code module.
Paste the following code into the module: Sub TextPlusTimeStamp() ActiveCell.Value = "DVC" & Format(Now, "yyyymmddhhnnss") End Sub
Click File > Save As, choose Excel Macro-Enabled Workbook (*.xlsm), and save the file.
Select the target cell, then go to Developer > Macros, choose TextPlusTimeStamp, and click Run.

Assign the Macro to a Button for Repeated Use
Use this method to make the text and timestamp macro easier to run on different cells without opening the Macro dialog each time.
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. Open your workbook: Launch WPS Office Spreadsheets and open the workbook where you want to add the macro.
- 2. Open the VBA editor: Press Alt+F11 or go to Developer > Visual Basic to open the VBA editor.
- 3. Add the macro code: Click Insert > Module, then paste the TextPlusTimeStamp macro code into the module.
- 4. Save the macro-enabled file: Save the workbook as an Excel Macro-Enabled Workbook (*.xlsm).
- 5. Run the macro: Select the target cell and run the macro from Developer > Macros or from a button.

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.




