Excel Data Connection Relative Path: How-To
In this article
Excel stores every data connection with a full file path, so a workbook that works on your PC breaks the moment it is opened on another machine or moved into a different folder. To use a relative path, you cannot type one into the connection properties: instead you make the workbook and the source file live in the same folder structure, then rebuild or edit the connection so its path is built from where the workbook itself sits. Practical ways are Power Query (load the source with a relative reference and let the query recalculate), a fixed folder scheme with one formula-driven file name, and the older trick of editing the connection string in the .odc file or via a stored connection. This guide walks through the Power Query route, which is the one Microsoft supports properly, and explains the limits of the others. Note that menu names can differ slightly by Excel version, device and region, and the steps below assume the Windows desktop version of Excel.
What You'll Need
- Excel for Windows with Power Query, or Excel for Mac with a recent build (Power Query support differs by version on Mac).
- Your source file (CSV, Text, or an Excel workbook) and the workbook that will hold the connection.
- A folder structure you control, ideally one folder containing both files.
- A backup copy of the workbook before you change an existing working connection.
Step-by-Step
- Decide the folder layout first. Create one project folder, for example Reports. Put the workbook that needs the data inside it, and put the source file in a subfolder such as Data. A predictable layout is what makes the relative reference reliable later. Write down the names exactly, including spaces.
- Save both files to that folder. Close the source file if it is open in another program; a file locked by another application cannot be read by a query. Save the workbook you are building so its location is fixed before you add a connection.
- Open the data connection through Power Query. On the Data tab, in the Get & Transform Data group, choose Get Data and point to the source. For a CSV, choose From File > From Text/CSV; for an Excel workbook, choose From File > From Workbook. Browse to the source inside your project folder and confirm.
- Load it as a query, not straight to a table. In the preview window choose Transform Data rather than Load. This opens the Power Query Editor where you can see and edit the path it generated.
- Inspect the source step. In the Applied Steps pane, click the first step (it usually starts with the source file name) and look at the formula bar. The path appears as a fixed text string. That is the full path you want to replace.
- Rewrite the reference to start from the workbook itself. Replace the absolute file path in the step with a reference that begins with the workbook's own folder. The standard, documented pattern is to filter the first column by the file name, then use a folder query, but a simpler and robust option is to build a helper query that reads the workbook's own location. In the Query Editor choose Home > Advanced Editor and use the documented relative-reference pattern rather than hand-guessing syntax; if you are not comfortable editing M code, keep the layout fixed and move the whole folder together instead (see the next step).
- Use the fixed-layout shortcut if editing M feels risky. Keep the connection absolute but always keep the workbook and source in the same relationship to each other. When you move the project, move the entire project folder, not the files individually. The connection then needs only one update at move time: open Data > Queries & Connections, right-click the connection, and check the source path. This is not a true relative path, but it removes the most common breakage.
- For Excel-to-Excel connections, use the stored connection rename trick. If you used Data > Get Data > From File the workbook stores the connection in the workbook file. If you used a Microsoft Query or the older import wizard, Excel may store the path in the connection string. Renaming or editing a stored .odc file is possible, but the path is still absolute inside it. Treat this as a reason to standardise on Power Query instead.
- Test with a deliberate move. Save the workbook, close it, copy the whole project folder somewhere else, reopen and refresh (right-click the query and choose Refresh, or use Data > Refresh All). If the data reloads from the copied folder, the reference is travelling correctly.
- Make the test meaningful. After copying, open the workbook in the copied folder while the original still exists but is not open. If the data still appears, you have at least a working absolute path pointing at the wrong place; if the query fails with a "file not found" message, read the exact path in the error to see what it is looking for.
Common Mistakes
- Trying to type a relative path into the connection string. Excel resolves connection strings against the current working directory, not the workbook folder. A path like Data\sales.csv may work when Excel is launched from one folder and fail when launched from a shortcut. Do not rely on it.
- Moving one file instead of the folder. The single biggest cause of broken connections. Move the whole folder tree together.
- Leaving the source open. A source workbook open in another Excel window is locked and can return stale data or an error. Close it before refreshing.
- Refreshing without saving. Power Query stores its definition in the workbook. An unsaved workbook can lose the edited query definition if Excel closes unexpectedly.
- Assuming it works on Mac and Windows alike. Paths use different separators, and Power Query support on Mac differs. Test on both if the workbook is shared.
Tips
- Keep file names simple: no ampersands, no very long names, and avoid spaces if you plan to edit the query code. Rename the source before building the query, not after.
- Use a consistent structure such as Project > Data for every project; then the same relative pattern works everywhere.
- If the workbook is shared by email, relative paths do not travel with the attachment. Share the folder (OneDrive or a network share) and keep everyone working from the same copy, or the connection must be rebuilt on each machine.
- Refresh on open: in Queries & Connections, right-click the connection and look for Properties, where you can tick the refresh-on-open option. This reduces stale data after a move.
- Document the folder layout inside the workbook, on a small Read Me sheet, so the next person knows where the data must sit.
Troubleshooting
File not found or path not valid. Open the query in the editor, click the source step and read the path in the formula bar. It is almost always an absolute path pointing at the old location. Rebuild the step by pointing to the file in the current location, then save.
Data refuses to refresh. Close the source file. If it is still locked, check whether it is open in another Excel window or on another PC on a network share, and whether the folder permissions have changed. Refreshing after a permissions change, sign out of the network share and back in, then refresh.
It works for you but not for a colleague. Your colleague does not have the source file at the path Excel is looking for. Either share the whole folder or rebuild the connection on their machine. If the workbook arrives by email, this is expected; a relative path cannot reach a file that was never delivered.
The query loads the wrong data. You have a working path, just not the right one. Check the file name in the error or in the query's source step; a duplicated source file in another folder is a common culprit.
You edited the advanced editor and the query now errors. Undo the change with Ctrl+Z in the editor, or delete the query and rebuild it from the source; a broken M expression is faster to rebuild than to debug.
Frequently Asked Questions
Can I just type a relative path in the connection properties?
No. The connection string expects a full path or a network location. Relative behaviour has to come from the query or from keeping the folder structure consistent.
Does a relative path work if I email the workbook?
No. The recipient does not have your folder or source file. Email the data inside the workbook, or share a folder instead.
Will Power Query keep the relative reference when I copy the folder?
Yes, if the query was built to resolve the file from the workbook's own location. If the reference was absolute, copying the folder does not help and the query will still point at the old location.
Does this work on Excel for Mac?
Power Query exists on recent Mac versions but the menus and support differ from Windows. Check your version, and test the copied-folder scenario before sharing.
What about a connection to a database or server?
Relative paths apply to files. Server connections use a server name and database name, so those need a shared server or a parameterised query, not a folder-relative path.
Do I need to refresh after moving the workbook?
Always. Saved data in the workbook is the old snapshot. Refresh so the query re-resolves the path and pulls current data.