Forum

What is the best wa...
 
Notifications
Clear all

What is the best way to update a core query used across multiple different workbooks and data models?

2 Posts
2 Users
0 Reactions
95 Views
(@louis)
Posts: 2
Active Member
Topic starter
 

Hi,

Currently I have a get and transform query that is used to pull our scheduled production for upcoming weeks and transform it into a usable data table that gets loaded into Power Pivot, this scheduling file is done in Excel and each worksheet shows production for each week of the year.

I have multiple workbooks that use this particular transform query. Currently I am just copying the query and pasting into Queries and Connections of a new workbook when I need to reuse it, however, if I ever need to make an edit to the query I have to go into each and every workbook and make the same edit in each one.

Is there a better way of managing a core query that is used across multiple workbooks so that if I ever need to make an edit I only have to do it to the main query, all the rest can be updated?

Thank you.

 
Posted : 16/11/2021 6:40 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Louis,

You'll have to use vba for this.

Basically, make changes in only 1 workbook query, and the query text will become the reference for all other books:

queryFormula=ThisWorkbook.Queries.Item("Query1").Formula

Set oledb = Workbooks("x.xlsx").Connections("Query - Query1").OLEDBConnection
Workbooks("x.xlsx").Queries.Item("Query1").Formula=queryFormula
oledb.Refresh
Set oledb = Workbooks("y.xlsx").Connections("Query - Query1").OLEDBConnection
Workbooks("y.xlsx").Queries.Item("Query1").Formula=queryFormula
oledb.Refresh

 

Of course, a loop can be built from a folder files, or from a list of locations.

See an idea here: https://stackoverflow.com/questions/60158029/update-queries-in-excel-using-vba

 
Posted : 17/11/2021 10:44 am
Share: