VBA & Macro Problems

How to Refresh Excel Data While a VBA UserForm is Open

Nimra MalikNimra Malik Oct 26, 2026 868 views

Question details

The user needs to refresh worksheet data, background queries, or external connections without closing an active VBA UserForm in Excel.

How to Refresh Excel Data While a VBA UserForm is Open
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

2
Change Form to Modeless

Locate the macro that calls your UserForm. Change the launch code to include the modeless parameter, for example: UserForm1.Show vbModeless.

3
Insert DoEvents Command

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.

4
Adjust Query Properties

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 DoEvents and Modeless UserForms
Disabling Background Refresh: If you uncheck 'Enable background refresh', Excel forces external data queries to complete before executing the next line of your VBA code, preventing race conditions.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website and download the free installation package.
  2. 2. Install the Software: Run the installer and follow the quick on-screen prompts to set up WPS Office on your computer.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheet and open your existing .xlsx or .xlsm files to continue your work seamlessly.
High compatibility with Microsoft Excel (.xls, .xlsx, .xlsm) formats.Premium version supports VBA macros for complex automation tasks.Familiar ribbon interface makes migration completely effortless.Lightweight installation saves system resources and runs smoothly.
microsoft office alternative - wps office

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.