Excel Error Codes

Fix Excel Run-Time Error 9 When Opening a UserForm in WPS Spreadsheets

Kushani NimanthikaKushani Nimanthika Nov 13, 2026 869 views

Question details

The user needs to identify and fix the cause of Run-time error 9 when a worksheet button attempts to open an Excel UserForm in WPS Spreadsheets, even though the form display code appears correct.

Fix Excel Run-Time Error 9 When Opening a UserForm in WPS Spreadsheets
Product
WPS Spreadsheets
Device & OS
not provided
Scenario
A worksheet button is supposed to open a UserForm, and the button or form display code appears correct, but the form fails to load.
Observed behavior
Run-time error 9 is triggered when the UserForm initialization code or button code references a worksheet named TEAMS_INFOS that does not exist or does not exactly match the actual sheet name.
Before you start

Before editing VBA, open the VBA editor and note the exact tab names of all worksheets, including spaces and punctuation. Run-time error 9 is usually a subscript out of range caused by a mismatch between the VBA worksheet reference and the actual sheet name.

Solution 1Recommended

Check and Correct the Worksheet Name in UserForm_Initialize or Button Code

Use this solution when the UserForm opens from a worksheet button but immediately stops with Run-time error 9 and the display code itself looks correct.

Run-time error 9, also known as “Subscript out of range,” commonly occurs when VBA refers to a worksheet that does not exist or whose name is not spelled exactly as it appears on the tab. In this case, the likely cause is ThisWorkbook.Worksheets("TEAMS_INFOS") in the UserForm_Initialize event.

1
Open the VBA editor and locate the UserForm code

In WPS Spreadsheets, press Alt+F11 to open the VBA editor. In the Project Explorer, double-click the UserForm and locate the UserForm_Initialize procedure or the macro that runs when the worksheet button is clicked.

2
Check the exact worksheet name in the VBA reference

Find the line that uses ThisWorkbook.Worksheets("TEAMS_INFOS"). Compare the name inside the quotation marks with the exact text shown on the worksheet tab, including spaces, underscores, punctuation, and letter case.

3
Update the worksheet reference or rename the worksheet

Either rename the worksheet tab to match the VBA string exactly, or update the code to the correct worksheet name. For example, if the tab is “TEAMS INFOS” with a space, change the code to ThisWorkbook.Worksheets("TEAMS INFOS").

4
Save and test the UserForm

Save the VBA project, return to the worksheet, and click the button again to confirm that the UserForm opens without Run-time error 9.

Check and Correct the Worksheet Name in UserForm_Initialize or Button Code
Worksheet reference corrected: Run-time error 9 disappears when the VBA sheet reference exactly matches an existing worksheet name.
WPS Spreadsheets VBA fix

Fix VBA Run-Time Error 9 in WPS Spreadsheets

Open the WPS Spreadsheets VBA editor, locate the UserForm initialization or button code, and update the worksheet reference to match the actual sheet name so the form opens correctly.

  1. 1. Open the VBA editor: In WPS Spreadsheets, press Alt+F11 or go to Developer > Visual Basic to open the VBA editor.
  2. 2. Select the UserForm: In the Project Explorer, double-click the UserForm and locate UserForm_Initialize or the button macro that calls it.
  3. 3. Update the worksheet name: Change ThisWorkbook.Worksheets("TEAMS_INFOS") to the exact worksheet tab name, or rename the sheet to match the code.
  4. 4. Run and test the macro: Save the project, close the editor, and click the worksheet button to verify the UserForm opens without Run-time error 9.
Resolves the UserForm loading failure by fixing the exact worksheet referenceWorks with Excel workbooks that use VBA macros and UserFormsPreserves .xlsm and .xlsx compatibility when editing and saving macro-enabled workbooksProvides a free, familiar ribbon and VBA editor environment
QA img-9

Frequently Asked Questions

Why does Run-time error 9 appear when I open a UserForm?

It usually means a VBA subscript is out of range, often because the code references a worksheet that does not exist or has a different name. Check the UserForm_Initialize event and compare the sheet name in the code with the actual worksheet tab.

How do I open the VBA editor in WPS Spreadsheets?

Press Alt+F11, or enable the Developer tab and click Visual Basic. Then expand the project in the Project Explorer and double-click the UserForm or module that contains the code.

Do spaces or punctuation matter in worksheet names?

Yes. The VBA string must exactly match the tab name, including spaces, underscores, punctuation, and letter case as needed. For example, TEAMS_INFOS is not the same as TEAMS INFOS.

Can I fix Run-time error 9 without renaming the worksheet?

Yes. Update the VBA code string to match the existing sheet name, or use the sheet’s CodeName property instead of a hard-coded worksheet name.

Will the fix work when opening the file in Microsoft Excel too?

Yes. Correcting the VBA sheet reference makes the macro compatible with both WPS Spreadsheets and Microsoft Excel, provided the referenced sheet exists in the workbook.