VBA & Macro Problems

How to Reference an Excel VBA UserForm from a Standard Module

John WilsonJohn Wilson Nov 3, 2026 871 views

Question details

The user needs to pass an Excel VBA UserForm to a standard module so a procedure can dynamically loop through its controls without calling the specific form by name.

How to Reference an Excel VBA UserForm from a Standard Module
Product
Excel / WPS Spreadsheet
Device & OS
not provided
Scenario
Writing a VBA macro where reusable code located in a standard module must interact with the controls (like text boxes or buttons) of a UserForm.
Observed behavior
The user requires the correct syntax and object data typing to successfully pass the UserForm context to the external standard module procedure.
Before you start

Ensure that the Developer tab is enabled in your spreadsheet application and that you have basic familiarity with navigating the Visual Basic Editor (VBE).

Solution 1Recommended

Pass the UserForm Object as a Parameter Using 'Me'

Use the 'Me' keyword inside the UserForm to pass the active form instance to a procedure stored in a standard module.

By passing the UserForm as an object parameter, you avoid hardcoding the form's specific name in your standard module. This approach makes your code highly reusable, allowing multiple different UserForms to utilize the exact same control-looping logic.

1
Define the Standard Module Procedure

In the VBE, insert a standard module and create a Sub procedure that accepts an object parameter. Define it like this: Sub ListControls(UsrForm As Object, FormName As String).

2
Write the Looping Logic

Inside your new standard module Sub, write a For Each loop to iterate over the form's controls. For example: For Each ctrl In UsrForm.Controls ... Next ctrl.

3
Call the Procedure from the UserForm

Open the UserForm's code module. Within an event (such as a CommandButton_Click), call your standard module procedure and pass the current form context using the 'Me' keyword: Call ListControls(Me, Me.Name).

Pass the UserForm Object as a Parameter Using 'Me'
Declaring the Parameter Type: If declaring the parameter 'As Object' or 'As MSForms.UserForm' results in a type mismatch error in your specific environment, try declaring it simply 'As Form'.
Advanced Spreadsheet Automation

Write and Execute VBA Macros Seamlessly in WPS Spreadsheets

WPS Office provides robust support for VBA macros, allowing developers to create UserForms, write standard modules, and automate complex workflows effortlessly.

  1. 1. Launch WPS Spreadsheets: Open WPS Office and start a new blank spreadsheet or open an existing macro-enabled workbook (.xlsm).
  2. 2. Access the Developer Tools: Navigate to the Developer tab on the top ribbon. If hidden, you can enable it from the WPS options menu.
  3. 3. Open the VBA Editor: Click the 'Visual Basic' icon or press ALT + F11 to launch the integrated VBA development environment.
  4. 4. Insert Modules and Forms: Right-click the project explorer to insert standard Modules or UserForms, and paste your code to start automating.
High compatibility with Microsoft Excel VBA syntax and UserForm controls.Integrated Visual Basic Editor with familiar debugging and code structuring tools.Lightweight architecture ensures that your macros and loops run incredibly fast.Cost-effective alternative for powerful daily spreadsheet data automation.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a Type Mismatch error when passing a UserForm to a standard module?

This occurs when the receiving parameter in the standard module restricts the data type incorrectly. Ensure the parameter is declared 'As Object', 'As MSForms.UserForm', or 'As Form' rather than hardcoding a specific form name like 'As UserForm1'.

What exactly does the 'Me' keyword do in VBA?

The 'Me' keyword is an implicitly declared variable in VBA. It refers specifically to the instance of the class or UserForm where the code is currently running, making it a reliable shortcut for passing the active form object to external procedures.

Can I edit and run VBA UserForms in WPS Office?

Yes. If you are using an edition of WPS Office that includes the VBA module, you can fully access the Visual Basic Editor, design UserForms, and execute standard module macros with high compatibility to Excel.