How to Create an Excel Button That Opens a VBA Pop-Up Form
Question details
The user wants to create a clickable button in a spreadsheet that triggers a VBA pop-up form to display detailed row information, including text fields and images.

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Building a custom interactive dashboard or log where clicking a button opens a detailed, user-friendly view of a specific record rather than scrolling horizontally.
- Observed behavior
- The user needs to successfully design a custom UserForm and write a script to populate it with data and image paths from the active row.
Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) so your VBA code is preserved. Additionally, verify that the Developer tab is enabled in your ribbon to access the Visual Basic Editor.
Build and Assign a VBA UserForm Macro
Use the VBA Editor to design a custom UserForm and write a script to populate it with row data when a button is clicked.
A VBA UserForm allows you to create a clean, customized pop-up window. By assigning a macro to a button or shape, you can automatically read data from the active row and display it in the form without navigating away from your main dashboard.
Press Alt+F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor.
In the top menu, click 'Insert' > 'UserForm'. Use the Toolbox to add TextBoxes (for text data like trade details), an Image control (for screenshots), and CommandButtons (like a Close button).
Create a new Module or double-click the form to view its code. Add a subroutine (e.g., Sub ShowTradeDetails) to capture the ActiveCell.Row. Map your cell values to the TextBox variables (e.g., .txtDate.Value = ws.Cells(selectedRow, 1).Value). Use the LoadPicture(imagePath) function to load the image into your Image control.
Go back to your spreadsheet, insert a Form Control button or a Shape. Right-click it, select 'Assign Macro', and link it to your new subroutine so the form opens when clicked.
Easily Create VBA UserForms with WPS Office
WPS Spreadsheet offers powerful built-in support for VBA and Macros, allowing you to design customized UserForms, write scripts, and automate your workflow with the same syntax used in Microsoft Excel.
- 1. Open WPS Spreadsheet: Launch WPS Office and open your macro-enabled (.xlsm) file containing your dataset.
- 2. Access the Developer Tab: Go to the 'Developer' tab on the ribbon and click 'VBA Editor' to launch the coding environment.
- 3. Design Your Form: Insert a new UserForm, drag and drop text fields or image controls, and paste your VBA script to load the active row data.
- 4. Assign Macro to Button: Insert a button shape directly on your sheet, right-click, choose 'Assign Macro', and select your UserForm trigger.

Frequently Asked Questions
Can I trigger the UserForm without clicking a button?
Yes, you can use the Worksheet_BeforeDoubleClick event in VBA. By adding code to the specific sheet module, double-clicking any cell in a row can automatically launch the UserForm populated with that row's data.
Why is my image not loading in the VBA UserForm?
This usually happens if the file path in your spreadsheet cell is incorrect or if the image format is unsupported. Ensure the cell contains the full absolute path (e.g., C:\Images\chart.jpg) and check that the file exists before passing it to the LoadPicture function.
How do I add a Close button to my UserForm?
Add a CommandButton to your UserForm in the VBA Editor. Double-click the button and enter 'Unload Me' in the click event code block. This will close the pop-up form and return you to the worksheet when clicked.
Do macros work the same way in WPS Office as in Excel?
Yes, WPS Office supports standard VBA code, including UserForms, ActiveX controls, and macro assignments. Most Excel macro scripts will run seamlessly in WPS Spreadsheet without modification.




