VBA & Macro Problems

Generate Work Item IDs from Excel Sheet Names with VBA in WPS Office

Phi Hung VoPhi Hung Vo Nov 13, 2026 869 views

Question details

The user needs a VBA function to generate sequential work item IDs from Excel worksheet names that share the same six-digit prefix.

Generate Work Item IDs from Excel Sheet Names with VBA in WPS Office
Product
WPS Spreadsheets
Device & OS
not provided
Scenario
A workbook contains worksheet names such as CH-2306011, and the user wants to derive a work packet ID and a two-digit sequence for sheets with the same six-digit prefix.
Observed behavior
Formula-only solutions based on GET.WORKBOOK may not update reliably when sheets are added or renamed.
Before you start

Save the workbook as a macro-enabled workbook (.xlsm) and make sure the Developer tab is available in WPS Spreadsheets before you open the VBA editor.

Solution 1Recommended

Create a VBA User-Defined Function to Generate Sequential Work Item IDs from Sheet Names

Use this method when you need sequential numbering that updates reliably after sheets are added or renamed, instead of a formula-only GET.WORKBOOK approach.

This VBA function receives the current sheet name, extracts the six-digit numeric prefix, counts worksheets that share that prefix, and returns the result as a two-digit sequence such as 01 or 02.

1
Open the VBA editor in WPS Spreadsheets

Click the Developer tab and select Visual Basic, or press Alt+F11, to open the Visual Basic for Applications editor.

2
Insert a standard module

In the Project Explorer, right-click the workbook project, choose Insert > Module, and create a new standard module.

3
Add the GetWorkItemID function

Paste a VBA function that loops through ThisWorkbook.Sheets, compares the six-digit prefix from the current sheet name, and returns Format(counter, "00").

4
Save as a macro-enabled workbook

Return to WPS Spreadsheets, click File > Save As, choose Excel Macro-Enabled Workbook (*.xlsm), and confirm the format.

Create a VBA User-Defined Function to Generate Sequential Work Item IDs from Sheet Names
Macro-enabled format is required: If the workbook is saved with a standard file extension instead of .xlsm, the VBA function may be removed or blocked.
WPS Spreadsheets VBA macro solution

Generate Sequential Work Item IDs from Worksheet Names with WPS Spreadsheets VBA

Open your workbook in WPS Spreadsheets, add the VBA user-defined function to a standard module, save as a macro-enabled .xlsm file, and use the function in a worksheet cell to produce a two-digit sequence such as 01 or 02 for sheets sharing the same prefix.

  1. 1. Download and open WPS Office: Install WPS Office, launch WPS Spreadsheets, and open the workbook that contains the CH-2306011 worksheet names.
  2. 2. Enable the Developer tab: Click Menu > Options > Customize Ribbon, enable the Developer tab, and return to the spreadsheet.
  3. 3. Open the VBA editor and insert a module: Click Developer > Visual Basic, insert a standard module from the Project Explorer, and paste the GetWorkItemID function.
  4. 4. Save as a macro-enabled workbook: Click File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm) so the VBA code remains available.
  5. 5. Enter the function and recalculate: In a worksheet cell, enter the function with the sheet name, then press F9 to recalculate after adding or renaming sheets.
Automates sequential work item numbers directly from worksheet name prefixesMaintains compatibility with Microsoft Excel .xlsm macro-enabled workbooksFree, lightweight spreadsheet app with a familiar Developer tab and VBA editorSimpler workbook maintenance compared with formula-only GET.WORKBOOK solutions
microsoft office alternative - wps office

Frequently Asked Questions

Why does a GET.WORKBOOK formula not update reliably when I add or rename sheets?

GET.WORKBOOK is a legacy macro-sheet function and sheet additions or renames do not always trigger a recalculation. A VBA user-defined function loops through the current workbook and returns an updated sequence when the workbook recalculates.

How do I open the VBA editor in WPS Spreadsheets?

Enable the Developer tab first. Then click Developer > Visual Basic or press Alt+F11 to open the VBA editor, and insert a standard module from the Project Explorer.

What file format should I use for a VBA function?

Save the workbook as an Excel Macro-Enabled Workbook with the .xlsm extension. If you save it as a normal .xlsx file, the VBA function may be removed or blocked.

How do I force the work item IDs to update after renaming a sheet?

Update the cell that passes the sheet name to the function, then press F9 or click Formulas > Calculate Now to force recalculation.

Can this method generate IDs for sheets that do not share the same six-digit prefix?

The example function counts only sheets whose six-digit numeric prefix matches the current sheet. You can adapt the prefix condition in the VBA code if your workbook uses a different naming rule.