Dynamic Filepath for Excel Power Query Source

lucausa75

New Member
Joined
Oct 15, 2021
Messages
22
Office Version
  1. 2013
Platform
  1. Windows
Dear All,

I have an Excel Power Query I need to make the Source as dynamic based on the value on MyPN!K2 cell as in the below screenshot
Image

to have this line Source = Excel.Workbook(File.Contents("C:\TEST\MyFile\January2024.xlsm"), null, true), becaming Source = Excel.Workbook(File.Contents(MyPN!K2), null, true),

Any way to do it?
Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You have to give that cell a Named Range. Once you do that, you can do
Power Query:
=Excel.CurrentWorkbook()
and your named range should pop up. You can then bake it into that formula.
 
Upvote 0
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Path= Excel.CurrentWorkbook(){[Name="MyPN!K2"]}[Content]{0}[DATA SOURCE]
Source = Excel.Workbook(File.Contents(Path), null, true)
 
Upvote 0
I got this error despite "MyPN" folder exists in my excel file

2024-02-06 10_57_54-Window.png
 
Upvote 0
As said previously, you need to name that cell, not use its address in PQ (that will not work).
 
Upvote 0
Select the cell, then in the name box on the left of the formula bar, type a name for the cell - e.g. FilePath
 
Upvote 0
Select the cell, then in the name box on the left of the formula bar, type a name for the cell - e.g. FilePath
Thanks for your help but I'm getting the same error as Excel is not recognize the name of the folder:
2024-02-06 10_57_54-Window.png
 
Upvote 0
You need to replace the "MyPN!K2" in that formula with whatever name you used - e.g. "FilePath"
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,128
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top