Power Query Problems

Fix SELECT * FROM Query Name Error in Excel Power Query VBA

Nimra MalikNimra Malik Oct 26, 2026 868 views

Question details

The user encounters an error when executing recorded VBA macros containing SQL-style commands like 'SELECT * FROM [Query Name]' for Power Query connections.

Fix SELECT * FROM Query Name Error in Excel Power Query VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
Running a recorded VBA macro to create or refresh a Power Query table.
Observed behavior
Excel rejects the SQL-style SELECT command because Power Query M queries are incompatible with recorded OLE DB SQL commands.
Before you start

Ensure you have saved a backup copy of your Excel workbook containing the VBA code before modifying the macro to prevent any loss of complex Power Query configurations.

Solution 1Recommended

Refresh Existing Queries via ListObject or QueryTable

Instead of recreating the table with recorded OLE DB SQL commands, refresh the existing query directly.

Recorded macros often attempt to recreate the data connection using an OLE DB SQL string. Power Query utilizes M code, which frequently conflicts with standard SQL queries like 'SELECT * FROM [Query Name]'. Refreshing the existing object circumvents this conflict.

1
Open the VBA Editor

Press Alt + F11 in Excel to open the Visual Basic for Applications editor.

2
Locate the Recorded Macro

Find the module containing your recorded macro and locate the code block that includes the 'SELECT * FROM [Query Name]' command.

3
Remove Re-creation Code

Delete or comment out the block of code attempting to recreate the query table.

4
Insert the Refresh Command

Replace the deleted block with a VBA command to refresh the specific table, such as Sheets("Sheet1").ListObjects("Table1").QueryTable.Refresh BackgroundQuery:=False.

5
Use RefreshAll (Alternative)

Alternatively, you can use the ThisWorkbook.RefreshAll command to update all data connections in the workbook simultaneously.

Refresh Existing Queries via ListObject or QueryTable
Best Practice: Refreshing an existing query connection is faster and more stable than fully recreating it via VBA.
Free Microsoft Office alternative

Switch to WPS Office for Seamless Spreadsheet Management

While advanced Power Query VBA troubleshooting can be complex in Microsoft Excel, WPS Spreadsheet offers a highly compatible, lightweight, and user-friendly alternative for managing your daily data tasks. It handles mainstream Excel files seamlessly and features an intuitive interface.

  1. 1. Download WPS Office: Visit the official WPS website and download the free installation package.
  2. 2. Install the Application: Follow the on-screen instructions to install the lightweight WPS Office suite on your device.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheet and open your existing Excel workbooks to enjoy perfect compatibility and seamless data editing.
Highly compatible with Microsoft Excel formats (.xlsx, .xls, .csv).Free and lightweight alternative to Microsoft Office.Includes robust data analysis tools and pivot tables.Familiar user interface for a smooth transition without a learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the macro recorder create an invalid SELECT statement for Power Query?

The Excel macro recorder translates data connection actions into legacy OLE DB SQL queries. Power Query uses a specialized M language, making the recorded SQL command incompatible with the existing Power Query structure.

Can I use SQL to query a Power Query connection in VBA?

Generally, no. Power Query relies on M language scripts. You should manipulate the query formula directly using VBA via the WorkbookQuery.Formula property rather than executing SQL SELECT statements.

How do I find the correct ListObject name to refresh via VBA?

Select any cell inside your Power Query output table, navigate to the 'Table Design' tab in the Excel ribbon, and locate the 'Table Name' box on the far left. Use this name in your VBA ListObjects("TableName") reference.