WPS Spreadsheet VBA: Populate a UserForm ComboBox with Open Worksheets
Question details
You need to populate a VBA UserForm ComboBox with worksheets from all open workbooks.
- Product
- WPS Spreadsheet VBA UserForm
- Device & OS
- not provided
- Scenario
- A UserForm should display each open workbook and its worksheets so the user can select a workbook-worksheet pair.
- Observed behavior
- The ComboBox is not automatically populated when the UserForm opens.
Open all workbooks that should appear in the list and confirm that the UserForm contains a ComboBox named ComboBox1. Make sure macros are enabled in WPS Spreadsheet before testing the form.
Populate the ComboBox when the UserForm opens
Use the UserForm Initialize event to scan every open workbook and add each worksheet to the ComboBox.
The Workbooks collection contains all currently open workbooks. The nested Worksheets loop adds entries in the format WorkbookName!WorksheetName, making each selection identifiable.
Place the initialization event in the UserForm's code module, not in a standard module. Use a standard module only for the procedure that displays the form.
In WPS Spreadsheet, open the VBA editor, locate the UserForm in the project pane, and choose View Code. From the left procedure drop-down, select UserForm; from the right procedure drop-down, select Initialize.
Enter this code in the UserForm module: Private Sub UserForm_Initialize()\n Dim book As Workbook, sheet As Worksheet\n\n Me.ComboBox1.Clear\n For Each book In Workbooks\n For Each sheet In book.Worksheets\n Me.ComboBox1.AddItem book.Name & "!" & sheet.Name\n Next sheet\n Next book\nEnd Sub
In the VBA editor, choose Insert > Module and add a procedure such as Sub ShowWorksheetPicker()\n UserForm1.Show\nEnd Sub. Replace UserForm1 with the actual name of your form, then run ShowWorksheetPicker to display it.
Open two or more workbooks with worksheets, run the form-launching macro, and open the ComboBox. Each open workbook and worksheet should appear as a separate entry.
Match the code to your form and control names
Use this check when the form opens but the ComboBox remains empty or VBA reports an object-name error.
Build a worksheet picker UserForm in WPS Spreadsheet
WPS Spreadsheet can run the VBA UserForm initialization code needed to list worksheets from all open workbooks. Create the form, add the ComboBox event code, and launch the form from a standard module.
- 1. Open WPS Spreadsheet and enable macros: Launch WPS Spreadsheet, open the macro-enabled workbook, and allow macros when prompted.
- 2. Create or open the UserForm: Open the VBA editor, select the workbook project, and insert or open the UserForm containing a ComboBox.
- 3. Add the Initialize event: Open the UserForm code window and place the Workbooks and Worksheets loop in the UserForm_Initialize event.
- 4. Add the form launcher: Choose Insert > Module, add a procedure that calls UserForm1.Show, and replace UserForm1 with your actual form name.
- 5. Run and verify the form: Open the target workbooks, run the launcher macro, and select a workbook-worksheet entry from the ComboBox.

Frequently Asked Questions
Where should the worksheet-populating VBA code be placed?
Place it in the UserForm code module under the UserForm_Initialize event. Do not place this event procedure in a standard module.
Why is the ComboBox empty when the UserForm opens?
Check that the ComboBox name matches the code, that the target workbooks are open in the same WPS Spreadsheet session, and that macros are enabled. The code clears and fills the list during UserForm initialization.
How do I display the UserForm from a macro?
Open the VBA editor, choose Insert > Module, and add a procedure such as Sub ShowWorksheetPicker() followed by UserForm1.Show and End Sub. Replace UserForm1 with the actual form name.
Can the ComboBox show worksheets from multiple workbooks?
Yes. The outer For Each book In Workbooks loop scans every open workbook, while the inner For Each sheet In book.Worksheets loop adds each worksheet.
How can I identify the selected workbook and worksheet later?
Read the ComboBox value, which has the format WorkbookName!WorksheetName. For more reliable processing when names may contain similar text, store workbook and worksheet references in separate controls or map each list index to the corresponding objects.




