VBA & Macro Problems

How to Keep an Excel Worksheet’s Last-Modified Date from Changing on Open in WPS Office

Rana GarciaRana Garcia Nov 13, 2026 869 views

Question details

The user needs a VBA timestamp in cell B5 to update only when the worksheet changes and to remain unchanged when the workbook opens without edits.

How to Keep an Excel Worksheet’s Last-Modified Date from Changing on Open in WPS Office
Product
WPS Office Spreadsheets
Device & OS
not provided
Scenario
A user has an Excel-compatible workbook with a VBA-managed last-modified timestamp in cell B5 and wants to prevent opening the file from refreshing that timestamp when no edits are made.
Observed behavior
The timestamp in cell B5 remains unchanged when the workbook opens without edits and updates only after a worksheet change.
Before you start

Open the workbook in WPS Office Spreadsheets and press Alt+F11 to open the VBA editor. Locate the worksheet module that contains cell B5, and review the ThisWorkbook and worksheet modules for existing Workbook_Open or Worksheet_Activate code before adding new VBA.

Solution 1Recommended

Use the Worksheet_Change Event to Update the Timestamp Only on Real Edits

Use this when you want cell B5 to stay unchanged during workbook open and update only after a worksheet cell is changed.

Worksheet_Change runs only when cells on that sheet change, not when the workbook opens. Disabling events while writing the timestamp prevents the change event from re-triggering itself.

1
Open the VBA editor and select the worksheet module

Open the workbook in WPS Office Spreadsheets, press Alt+F11, and select the worksheet module for the sheet that contains cell B5 in Project Explorer.

2
Insert the Worksheet_Change timestamp code

In the worksheet module, paste the following procedure. It checks that the changed range intersects the used range, disables events before writing to B5, writes the current time, and re-enables events even if an error occurs: Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Me.UsedRange) Is Nothing Then Application.EnableEvents = False On Error GoTo CleanExit Range("B5").Value = Now CleanExit: Application.EnableEvents = True End If End Sub

3
Optional: Exclude B5 itself from the monitored range

If another process intentionally changes B5 and that change should not refresh the timestamp, add a condition to ignore B5, for example by checking If Not Intersect(Target, Range("B5")) Is Nothing Then Exit Sub before writing to B5.

4
Save and test the timestamp behavior

Save the workbook as a macro-enabled file, close it, reopen it without editing, and confirm B5 remains unchanged. Then change any other cell in the used range and confirm B5 updates.

Use the Worksheet_Change Event to Update the Timestamp Only on Real Edits
Expected result: Cell B5 now updates only when a worksheet cell changes and stays unchanged when the workbook opens without edits.
WPS Office VBA support

Keep Your Excel Last-Modified Date Stable on Open with WPS Office VBA

WPS Office Spreadsheets supports Excel-compatible VBA, so you can edit the Worksheet_Change event to update cell B5 only when users actually change the sheet. The timestamp remains unchanged when the workbook opens without edits.

  1. 1. Open the workbook in WPS Office Spreadsheets: Launch WPS Office Spreadsheets, open the macro-enabled workbook that contains the timestamp in cell B5, and enable macros if prompted.
  2. 2. Open the VBA editor: Press Alt+F11 to open the VBA editor and select the worksheet module for the sheet that contains cell B5.
  3. 3. Enter the Worksheet_Change timestamp code: Add the Worksheet_Change procedure that writes the current time to B5 only when a worksheet cell changes, and disable events while writing to avoid recursion.
  4. 4. Save and test the timestamp behavior: Save the workbook as a macro-enabled Excel file, close and reopen it without editing to confirm B5 remains unchanged, then edit a cell to confirm B5 updates.
Keeps the last-modified timestamp stable on open and updates it only after actual sheet changesUses Excel-compatible VBA events such as Worksheet_Change and Workbook_OpenReads and saves Microsoft Excel .xlsm macro-enabled workbooks while preserving VBA codeOffers a free, familiar Office interface with a built-in VBA editor
microsoft office alternative - wps office

Frequently Asked Questions

Why does the timestamp in B5 still change when I open the workbook?

Check ThisWorkbook > Workbook_Open and each sheet’s Worksheet_Activate code in the VBA editor. Any Range or Cells write to B5 at open will refresh the timestamp; move the update to Worksheet_Change or remove the open-time write.

Which VBA event should I use to update a cell only when the worksheet changes?

Use the Worksheet_Change event in the worksheet module for the sheet containing B5. It fires only when cells in that worksheet are changed, so workbook open without edits leaves the timestamp unchanged.

How do I open the VBA editor in WPS Office Spreadsheets?

Open the workbook in WPS Office Spreadsheets, press Alt+F11, and choose the target worksheet module in Project Explorer. If Project Explorer is hidden, show it from the View menu in the VBA editor.

Do I need to disable events in the timestamp macro?

Yes. Set Application.EnableEvents = False before writing the timestamp to B5 and set it back to True immediately after, including an On Error GoTo label, so a failed write does not leave events disabled.

Will WPS Office preserve my Excel VBA timestamp macro when saving?

Yes. Save the file as an Excel macro-enabled workbook (.xlsm) from WPS Office Spreadsheets. The VBA procedure and timestamp behavior are retained when reopened in WPS Office or Microsoft Excel.