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

collin8579

New Member
Joined
Oct 31, 2017
Messages
20
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

  • Query1.PNG
    Query1.PNG
    17 KB · Views: 74
  • Pacedata2.PNG
    Pacedata2.PNG
    22.7 KB · Views: 75

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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
 
Upvote 0
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
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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