logo
search
VBA & Macro Problems

How to Run SQL-Style Queries on Excel Workbook Data Using Office Scripts

Ayan MasoodAyan Masood Oct 15, 2026 868 views

Question details

The user is trying to perform complex relational SQL-style queries directly on workbook data using Excel Office Scripts but is unable to find a built-in ADO-style SQL engine.

How to Run SQL-Style Queries on Excel Workbook Data Using Office Scripts
Product
Microsoft Excel
Device & OS
not provided
Scenario
Executing advanced data manipulations, complex table joins, and direct column comparisons within an Excel workbook environment using automated scripts.
Observed behavior
Excel Office Scripts do not provide a native ADO-style SQL engine, making it difficult to run relational queries such as complex joins or comparing values across different columns.
Before you start

Assess the complexity of your data manipulation needs. While standard TypeScript can handle basic filtering in Office Scripts, complex relational joins are better handled by Power Query or by exporting your data to a dedicated SQL database.

Solution 1Recommended

Use Power Query for Advanced Relational Transformations

Since Office Scripts lack an SQL engine, Power Query is the most powerful native Excel alternative for joining tables, filtering records, and merging datasets without writing complex code.

Power Query operates similarly to a relational database engine. It provides a visual interface for transforming data, allowing you to perform inner, outer, and anti-joins just like you would with SQL.

1
Load your data

Go to the 'Data' tab on the Excel ribbon, click 'Get Data', and select your data source (e.g., 'From Table/Range' if the data is already in your workbook).

2
Merge queries

In the Power Query Editor, click 'Merge Queries' on the Home tab to combine two tables based on a matching column, replicating a SQL JOIN operation.

3
Filter and transform

Use the column dropdowns to filter data or add custom conditional columns to replicate SQL WHERE and CASE statements.

4
Load data back to Excel

Click 'Close & Load' to output your fully transformed and joined dataset into a new Excel worksheet.

Use Power Query for Advanced Relational Transformations
Automation Tip: You can use Office Scripts to refresh your Power Query connections automatically by calling 'workbook.refreshAllDataConnections()'.
Free Microsoft Office alternative

Handle Complex Spreadsheet Data and Macros with WPS Office

If modern Excel Office Scripts fall short because they lack traditional ADO SQL connectivity, WPS Office provides a robust, highly compatible environment. WPS Spreadsheets supports classic VBA macros natively, allowing you to run traditional ADO database connections and SQL queries directly on your workbook without complex workarounds.

  1. 1. Download and Install: Download WPS Office for free from the official website and follow the quick installation prompts.
  2. 2. Open Your Workbook: Launch WPS Spreadsheets and seamlessly open your existing .xlsx or .xlsm files.
  3. 3. Access Macro Tools: Navigate to the Developer tab to access powerful Macro and VBA tools for advanced SQL querying.
Fully compatible with Microsoft Excel (.xlsx, .xls, .xlsm, .csv) file formats.Supports classic VBA, enabling standard ADO and OLEDB SQL querying.Free, lightweight, and fast installation compared to standard Office suites.Familiar ribbon interface ensures zero learning curve for existing Excel users.
microsoft office alternative - wps office

Frequently Asked Questions

Does Excel Office Scripts support ADO connections?

No. Office Scripts run in a secure cloud-based environment using TypeScript and do not support the legacy ActiveX Data Objects (ADO) library required for native SQL queries. For ADO support, traditional VBA is required.

Can I query an Excel table using SQL without external tools?

Natively, Excel does not have an internal SQL engine that accepts standard SQL text queries directly on cells. However, Power Query uses the M formula language to accomplish the exact same relational tasks (joins, groupings, filtering) via a graphical interface.

Is Power Query better than Office Scripts for data joins?

Yes. Power Query is specifically designed for complex data shaping, merging, and relational joins. Office Scripts are better suited for automating repetitive formatting tasks and triggering custom workflows, rather than processing complex relational datasets.

How do I perform a VLOOKUP equivalent in Office Scripts?

You can simulate a VLOOKUP in Office Scripts by fetching the range values into an array and using the TypeScript 'find()' or 'filter()' methods to locate matching records across different rows.