vba to update advanced editor in power query

TaskMaster

Board Regular
Joined
Oct 15, 2020
Messages
55
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Good morning,

I am have begun using power query to format my data which is working rather well. The issue is that the data source seems to change and im wondering if there would be to automate updating this using vba. E.g. "Framework_F7_Daily_Base" might become "Framework_F8_Daily_Base" when the source data is refreshed. My initial thought was to use an input box & find & replace to update the number that would change but I can't seem to get it working. Does any one have any suggestions?

VBA Code:
Sub UpdateLinks()

'***********************************************************************************
      'Purpose: Update power query advanced editor with new source data
      'How:     Find and replace source data with new link
      'Outputs: Using InputBox to manually enter new data link
'***********************************************************************************

    Dim oQ As WorkbookQuery
    Dim xy As Variant
    Dim xx As Variant
    
    'Manually enter the updated DB Link
    
    xx = InputBox("Enter updated DB Link")
    xy = ThisWorkbook.Worksheets("xxxx").Range("xxxx")
    
    'Find queries using this table
    
    For Each oQ In ActiveWorkbook.Queries
        oQ.Formula = Replace(oQ.Formula,"Framework_" & xy"", xx"")
    Next

End Sub

Power Query:
    Source = AnalysisServices.Databases("SQLDB", [TypedMeasureColumns=true, Implementation="2.0"]),
    Framework_F7_Daily_Base = Source{[Name="Framework_F7_Daily_Base"]}
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Wouldn't it be easier to set up a parameter for your query that you can simply populate from either a named range or a table?
 
Upvote 0
Hi Rory,

I can give that a try, how would I link this up to the advanced editor as im not familiar with the M code?
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

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