How to Refresh Excel Data While a VBA UserForm is Open
Question details
The user needs to refresh worksheet data, background queries, or external connections without closing an active VBA UserForm in Excel.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Running an Excel workbook with background queries or external data connections while an interactive VBA UserForm is active.
- Observed behavior
- The VBA UserForm (whether modal or modeless) pauses or blocks worksheet updates, preventing data from refreshing normally until the form is closed.
Ensure that your workbook is saved and that you have basic familiarity with the VBA Editor, as resolving this requires modifying your existing macro code.
Use DoEvents and Modeless UserForms
Change the UserForm to modeless and insert DoEvents in your loop to allow Excel to process background tasks like data refreshes.
By default, UserForms are modal and take complete control of the application, halting background updates. Switching to a modeless form and yielding execution back to Excel allows background data connections to refresh.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
Locate the macro that calls your UserForm. Change the launch code to include the modeless parameter, for example: UserForm1.Show vbModeless.
If your UserForm relies on a continuous loop to check for data, insert the 'DoEvents' command inside the loop. This temporarily pauses the macro to let Excel process screen updates and background queries.
Go to the Data tab, click 'Queries & Connections', right-click your connection, and select 'Properties'. Under the Usage tab, uncheck 'Enable background refresh' if you want the macro to wait for the query to finish.

Use Application.OnTime for Scheduled Refreshes
Schedule a macro to run and refresh data periodically without keeping a constant loop running, freeing up the application to update data.
Try WPS Office for Powerful Spreadsheet Management
Dealing with complex Excel VBA issues and query conflicts can be challenging. WPS Office offers a lightweight, highly compatible alternative for your spreadsheet needs. It perfectly supports Microsoft Excel formats and offers a seamless migration experience with a familiar interface.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package.
- 2. Install the Software: Run the installer and follow the quick on-screen prompts to set up WPS Office on your computer.
- 3. Open Your Spreadsheets: Launch WPS Spreadsheet and open your existing .xlsx or .xlsm files to continue your work seamlessly.

Frequently Asked Questions
What is the difference between a modal and modeless UserForm in Excel?
A modal UserForm requires the user to close it before they can interact with the Excel worksheet again. A modeless UserForm, opened using 'vbModeless', allows the user to click, type, and edit the worksheet while the form remains visible on the screen.
Why does my macro freeze when pulling external data?
Macros often freeze during external data pulls because Excel's default behavior for many connections is to refresh in the background. If your macro doesn't yield execution time to the application, it causes a conflict. Using DoEvents or disabling 'Enable background refresh' forces the macro to coordinate with the data pull.
How does the DoEvents function work in VBA?
The DoEvents function temporarily pauses the execution of your VBA code, yielding control back to the operating system and Excel. This allows the program to process other pending events, such as screen repaints, button clicks, or completing background data refreshes.
Does WPS Office support VBA and macros?
Yes, the premium version of WPS Office includes robust support for VBA macros. You can open, edit, and run .xlsm files and custom VBA scripts with high compatibility compared to Microsoft Excel.




