Skip to content

Instantly share code, notes, and snippets.

@dannguyen
Last active February 26, 2025 18:14
Show Gist options
  • Save dannguyen/5a0f5a895c419966e44b6c25a4a2373b to your computer and use it in GitHub Desktop.
Save dannguyen/5a0f5a895c419966e44b6c25a4a2373b to your computer and use it in GitHub Desktop.
MacOS Excel Power Query M: How to fix DataSource.Error Access to the path '/yourpath.csv' is denied error

How to fix "DataSource.Error Access to the path '/yourpath.csv' is denied error" in macOS Excel Power Query

excel error box: [DataSource.Error] Access to the path '/Users/dan/Dropbox/mybook/mydata.csv' is denied.

One of the most incomprehensible errors I have ever run into, with Microsoft forums and ChatGPT/Claude being almost totally useless. Hopefully anyone else running into this situation will come across this gist and save themselves hours of frustration.

Huge thanks to Mr. Excel for the solution, with a major assist by r/excel

Background

power query editor error [DataSource.Error] Access to the path '/Users/dan/Dropbox/mybook/mydata.csv' is denied.

So you're trying to use macOS Excel's Power Query Editor to load an external file from disk, e.g. /Users/dan/Dropbox/mybook/mydata.csv, only to get this error:

• [DataSource.Error] Access to the path '/Users/dan/Dropbox/mybook/mydata.csv' is denied.
   Details 
     isRecoverable: True
     isExpected: True

I ran into this error when saving a workbook on Dropbox, and then trying to open and work on it from a different laptop. Opening the Excel workbook was fine, the error message came from the Power Query command that imported the CSV, e.g.

let
  Source = Csv.Document(
      File.Contents("/Users/dan/Dropbox/mybook/mydata.csv"), 
      [Delimiter = ",", Columns = 2, QuoteStyle = QuoteStyle.None]
  )
in
  Source

The computer that originally created and saved the workbook had no problems re-opening the book and working with the Power Query command. The other laptop just utterly refused to open the CSV. Even after granting Full Disk Access via macOS Settings » Privacy and Security options.

Solution

tl;dr: Have Excel ask you to grant access to that file. But since Excel (in my experience) won't even know to do that, you can force it to with a simple VB command referencing the file path.

1. Force Excel to ask for access privileges by executing VB code that refers to the file path

Go to the Microsoft Visual Basic editor inside of Excel (i.e. Developer ribbon » Visual Basic)

excel screenshot of VB editor

Then open up the "Immediate" code window, i.e. View » Immediate Window or use the keyboard shortcut Ctrl-Cmd-G.

Enter, then execute following benign code which simply tries to print the directory of the data file via a message alert box:

(obviously, replace with the absolute path to the file you're trying to access)

MsgBox Dir("/Users/dan/Dropbox/mybook/mydata.csv")
image

Executing that line of code will bring up a dialog box asking you to manually grant access to the given file.

Additional permissions are required to access the following files: /Users/dan/Dropbox/mybook/mydata.csv Microsoft Excel needs access to the file named "mydata.csv". Select the item to grant access.

image

Select the file and grant access:

image

It will likely ask you to grant access to the enclosing folder, so do that too:

image

The MsgBox command should successfully execute:

image

Save, and restart Excel. You should be good to go.

Note: You have to completely exit out of Excel, not just close the file.

Also: Enable "Allow combining data from multiple sources"

You already need to do this step anyway, whether you're on macOS or Windows:

In the Power Query Editor » Options » Privacy, be sure to enable the option that says:

Allow combining data from multiple sources. This could expose sensitive or confidential data to an unauthorized person.

image

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment