How to keep query connection alive when an xlsx file name is changed in a fixed folder address?

ODSCm

New Member
Joined
Dec 18, 2020
Messages
32
Office Version
  1. 2016
Platform
  1. Windows
Hello all,

I would like to connect an xlsx file in a folder. This folder address will not be changed however the excel file name will be changed. In this situation I do not want my connection to be broken.
Which ways are available to solve this problem?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
What will be changed about the file name? Will it be as simple as the xlsx file having a different date at the end? Or is it more of a random difference?
 
Upvote 0
What will be changed about the file name? Will it be as simple as the xlsx file having a different date at the end? Or is it more of a random difference?
Hello Thanks for reply Sorry I saw late your reply.
Name will be changed based on date. It is simply an xlsx export file from a system like JIRA. So you can think for example first 10 chr will remain fixed, but after then it will be always different.
 
Upvote 0
If there's SOMETHING consistent about the file name, you can use Get Data from FOLDER rather than a single file, and then filter the File Name to get the file you need. So if the file always starts with "2023", you filter the Filename to Begins With 2023, and then continue on from there.
Alternatively, you can put the Filename into a cell manually and then pull that into a Query and use that as the source of your main query.
The cell in question needs to be named like this:
1678128543864.png

At which point you can use Get Data from Table/Range to pull it in, then modify the M Code like this:
Power Query:
= Excel.CurrentWorkbook(){[Name="FileName"]}[Content]{0}[Column1]
Name that Query FileName, and then use this line in the Query for the actual file:
Power Query:
= Excel.Workbook(File.Contents("C:\Users\USERID\Desktop\" & FileName), null, true)
The first solution is preferable since it doesn't require any manual changes.
I should have used a different name for either the Named Range or the Variable to make it less confusing. Hope it's not too bad!
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,851
Members
449,194
Latest member
HellScout

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