Excel Extract Data from Closed Workbook Text File
In this article
- Background: Why Read a Closed Text File?
- How It Works: Power Query and Data Connections
- How to Choose the Right Method
- Step-by-Step: Power Query from a Closed Text File
- Common Problems and Misconceptions
- Comparison: Text File vs. Closed Excel Workbook
- Safety and Accuracy Considerations
- Frequently Asked Questions
Yes, Excel can extract data from a closed workbook saved as a text file (like .txt or .csv) without opening it, using Power Query (Get & Transform) or legacy Data Connection tools. You point Excel at the file path, and it reads the data directly from disk, even if the file is not open in Excel.
Background: Why Read a Closed Text File?
Workbooks saved as text files (.txt, .csv, .prn) are common exports from accounting systems, databases, and web tools. They are lightweight, easy to share, and do not require Excel to be installed on the source machine. The challenge arises when you want to refresh a report in Excel without manually opening and copying data each time. Reading a closed text file lets you build a live connection that pulls fresh data whenever the file changes, without leaving your main workbook.
How It Works: Power Query and Data Connections
Excel offers two main paths to read a closed text file:
- Power Query (Get & Transform) – available in Excel 2016 and later. It creates a query that stores the file path and import settings. When you refresh, Power Query re-reads the file from disk, even if it is closed.
- Legacy Data Connection (From Text/CSV) – in older Excel versions or when you use the “From Text” button. It creates a connection that can be refreshed, but it is less flexible than Power Query.
Both methods store the file path as a text string. Excel does not need the file open because it reads the file directly from the file system using the path. The data is not copied into the source file; it is pulled into your workbook only when you refresh.
How to Choose the Right Method
Your choice depends on your Excel version and how often the text file changes:
- Power Query – best for recurring imports, complex transformations, and when you need to refresh with one click. It works in Excel 2016, 2019, 2021, and Microsoft 365.
- Legacy “From Text” – okay for one-time imports or if you are on Excel 2013 or earlier. It is simpler but harder to modify after creation.
- VBA with OpenText – if you need to automate the import with a macro, you can use the Workbooks.OpenText method, which reads a text file without opening it as a workbook.
Step-by-Step: Power Query from a Closed Text File
- In Excel, go to the Data tab.
- Click Get Data → From File → From Text/CSV.
- Browse to the text file and select it. Do not open it in Excel first.
- Excel shows a preview. Check the delimiter (comma, tab, etc.) and data types.
- Click Load to import the data into a worksheet, or Transform Data to edit in Power Query Editor first.
- To refresh later, right-click the query in the Queries & Connections pane and choose Refresh.
The file can be closed during refresh. Excel reads it directly from the path you specified.
Common Problems and Misconceptions
One frequent misconception is that Excel must have the file open to read it. That is false for text files – Excel reads them from disk. However, if the file is a binary Excel workbook (.xlsx), you cannot read it with Power Query unless you use a separate add-in or VBA. For text files, the main issues are:
- File path changes – if you move the text file, the connection breaks. Update the path in the query or use a relative path.
- Delimiter mismatch – if the file uses semicolons but you choose commas, data lands in one column.
- Encoding issues – text files may be UTF-8, ANSI, or Unicode. Power Query usually detects it, but sometimes you need to set it manually in the import step.
- Refresh fails because the file is locked – if another program has the file open exclusively, Excel may not read it. Close the other program or use a copy.
Comparison: Text File vs. Closed Excel Workbook
Reading a closed .xlsx file is not natively supported in Power Query. You can only read an open Excel workbook, or use VBA with the Workbooks.Open method, which opens it invisibly and then closes it. That is slower and can cause issues if the file is large. Text files are simpler because they are plain data – no formulas, formatting, or macros – so Excel can parse them directly. If you need to pull from a closed .xlsx, consider converting it to a CSV or using a third-party library.
Safety and Accuracy Considerations
When you read a text file, Excel uses the file’s current content at the moment of refresh. There is no automatic update unless you set a refresh interval. If the file is updated by another process, your data may be stale until you refresh. Also, be careful with file permissions – if the file is on a network drive and you lack read access, the refresh fails. Always verify the data types after import; numbers stored as text can cause calculation errors. For sensitive data, be aware that the file path is stored in the query, so anyone with access to your workbook can see where the data comes from.
Frequently Asked Questions
Can Excel read a closed CSV file?
Yes, CSV is a text file. Use Power Query or the legacy From Text import. The file does not need to be open; Excel reads it from the path.
Why does my refresh fail when the file is closed?
Usually because the file path is incorrect, the file is locked by another program, or you lack read permissions. Check the path in the query and ensure the file exists.
Can I read a closed .xlsx file without opening it?
Not with Power Query directly. You can use VBA to open it invisibly, read the data, and close it, but that is not the same as a direct read. For a true closed-read, convert the .xlsx to a text format.
How do I refresh automatically from a closed text file?
In Power Query, right-click the query and go to Properties. Under Refresh control, set a refresh interval (e.g., every 15 minutes) or refresh when the file opens. That will re-read the closed file on schedule.
What if the text file has no header row?
In Power Query, during the import step, you can choose “First row as header” or leave it unchecked. If you leave it unchecked, Excel names the columns Column1, Column2, etc. You can rename them later.