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

collin8579

New Member
Joined
Oct 31, 2017
Messages
13
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
3,763
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
13
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
13
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,081,723
Messages
5,360,865
Members
400,602
Latest member
newaqua

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top