Changing Query Source with VBA Help: Excel file on network path

collin8579

New Member
Joined
Oct 31, 2017
Messages
17
Good morning,
I have queries that reference excel files on a network path,
In the attached picture my source is something like K:\ATT Cognos\STX Pace Data.xlsx
I need to be able to change it to different markets and refresh the query without having to go into the query manually,
I am looking for VBA solution, and have tried things like
With ActiveSheet.QueryTables.Add(Connection:=FilePath, Destination:=Range("$A$1"))

Worksheets(1).QueryTables(1) _ Connection := "TEXT;C:\My Documents\19980331.txt"

I haven't been able to figure out a solution that works and any help would be appreciated.
 

Attachments

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
4,257
if your sources have the same structure and headers then you can define a parameter which can be selected from DV list from the Excel sheet
 

collin8579

New Member
Joined
Oct 31, 2017
Messages
17
if your sources have the same structure and headers then you can define a parameter which can be selected from DV list from the Excel sheet
I have the DV list already< its how to associate that with the query source that I am asking
 

collin8579

New Member
Joined
Oct 31, 2017
Messages
17
Figured out how to do what I was trying to do: Advanced editor shows as follows.

let
Filepath = Excel.CurrentWorkbook(){[Name="Filepath"]}[Content]{0}[Column1],
Source = Excel.Workbook(File.Contents(Filepath), null, true),

Where the filepath variable in excel is a cell that has the dynamic filepath name pop up.
works well

Thanks!
 

Forum statistics

Threads
1,085,565
Messages
5,384,469
Members
401,903
Latest member
MarBer

Some videos you may like

This Week's Hot Topics

Top