Power Query Excel.Workbook Function: How to Use It
In this article
The Excel.Workbook function in Power Query returns a table that describes the structure of a workbook: its sheets, named ranges, tables, and defined names. You use it when you need to combine data from many workbooks or from multiple sheets whose names you do not know in advance. The function is available in Power Query in Excel and in Power BI Desktop; the exact menu labels can differ slightly by version and region.
What You'll Need
- Excel for Windows or Excel for Mac with Power Query (called Get & Transform in some versions), or Power BI Desktop.
- One or more .xlsx or .xlsm workbooks saved locally or in a folder you can reach.
- Basic familiarity with the Power Query Editor: the Queries pane, the formula bar, and the Applied Steps list.
Step-by-Step
- Open Power Query. In Excel, go to the Data tab and choose Get Data > From File > From Workbook (or From Folder if you are combining many files). In Power BI Desktop, use Home > Get Data > Excel workbook. The labels vary slightly between versions.
- Select the workbook and click Import. Power Query opens the Navigator window showing a preview of the sheets and tables it found.
- Do not click Load yet. Instead, click Transform Data to open the Power Query Editor. This is where the Excel.Workbook function becomes visible and editable.
- Find the Excel.Workbook step. In the Applied Steps pane on the right, look for a step named something like "Source" or "Navigation." Click it. The formula bar shows a call such as
Excel.Workbook(File.Contents("C:\Data\Book1.xlsx"), null, true). - Understand the three arguments. The first is the binary file content. The second is
useHeaders:nullmeans Power Query decides,trueforces the first row to be treated as headers, andfalsetreats all rows as data. The third isdelayTypes:truedelays type detection until you expand a column, which is usually faster and safer. - Expand the returned table. Excel.Workbook returns a table with columns such as Content, Name, Item, Kind, and Hidden. Click the expand icon (two arrows) in the Content column header and choose Expand. You will now see one row per sheet, table, or named range.
- Filter to what you want. Use the filter arrow on the Kind column to keep only Sheet, Table, or DefinedName. For example, keep Table to work only with Excel tables, which are more stable than sheet ranges.
- Drill into a single item by clicking the Table link in the Content column for the row you want. This creates a new query step that references that specific sheet or table.
- Combine multiple items by removing other columns, then clicking the Combine Files button (or expanding the Content column without filtering). Power Query will append the tables, matching columns by name.
- Clean up and load. Rename the query, remove helper columns, set data types, then choose Home > Close & Load > Close & Load To to place the result on a worksheet or in the Data Model.
Common Mistakes
- Using Excel.Workbook on a CSV file. The function expects a workbook binary. For CSV, use Csv.Document instead.
- Forgetting to expand the Content column. The raw output is metadata only; without expanding, you see sheet names but no data.
- Hard-coding a file path. If you move the workbook, the query breaks. Use a parameter or the Folder.Files pattern for portability.
- Relying on sheet names that change. If someone renames a sheet, a query that filters by Name will fail. Filter by Kind and position instead, or use named tables.
- Loading the metadata table by mistake. If you close and load before expanding, you get a list of sheets rather than the data.
Tips
- Set
delayTypestotruefor faster refreshes on large workbooks; apply types only to the columns you keep. - Prefer Excel Tables (Insert > Table) over plain ranges. Excel.Workbook lists them as Kind = Table, and they resize automatically.
- Use the Name column to filter for a specific table when you only need one.
- Keep a sample workbook in a fixed folder and point your query there while you build the logic, then swap to the Folder.Files pattern for production.
- Document the arguments in a comment step so future editors know why useHeaders or delayTypes was set a certain way.
Troubleshooting
- "We couldn't find the file" or a path error. Check that the file still exists at the path shown in the formula bar. If you moved it, edit the Source step and browse to the new location.
- Data appears as a single column or with wrong headers. Change the second argument of Excel.Workbook: try
trueif headers are on the first row,falseif they are not. - Refresh is slow. Set
delayTypestotrue, remove unused columns early, and filter rows before expanding. - "The column 'X' of the table wasn't found." A sheet or table was renamed or deleted. Re-open the Source step, re-expand, and reapply your filters.
- Combine Files fails. Check that the selected items have compatible column names. Rename columns in each source or use a transformation table to map them.
Frequently Asked Questions
Does Excel.Workbook work with .xls files?
It works with .xlsx and .xlsm. Legacy .xls files are not reliably supported; convert them to .xlsx first.
Can I use Excel.Workbook on a workbook open in another program?
Yes, but the file must not be locked for writing. Close it in Excel if refresh fails with a sharing error.
What does the Hidden column mean?
It indicates whether the sheet, table, or name is hidden in the workbook. Filter it to false to ignore hidden items.
Can I combine Excel.Workbook with Folder.Files?
Yes. Use Folder.Files to list workbooks in a folder, then call Excel.Workbook on each file's Content column. This is the standard pattern for combining many workbooks.
Why does my query return sheet names but no data?
You have not expanded the Content column. Click the expand icon and choose Expand to see the actual rows.
Does Excel.Workbook work in Power BI Desktop?
Yes, the function is the same. The menu path to reach it differs, but the formula and arguments are identical.