0

How to change Excel PowerQuery Paramaters with VBA?

i.e. These Paramaters:

Excel Power Query

Right now the Paramater has a value of 8, and is used in refreshing all other power queries. How can I change this paramater with VBA?

The Macro recorder does not show anything.

3
  • 1
    Do you frequently need to change the parameter? If so, you could pick up the value from a cell. Otherwise, just change the value in the M code. Commented Oct 8, 2018 at 14:05
  • Yes, I need to change it frequently. The reason the vba code simply copies the workbook an arbitrary number of times (changing the parameter in each one). The copied workbook is not a macro workbook, which is why I am using Query Parameters. Commented Oct 8, 2018 at 14:19
  • google.co.uk/… I partic like the ExcelIsFun versions. Commented Oct 8, 2018 at 14:21

1 Answer 1

4

Thanks to QHarr, I figured it out. Simply edit the Power Query M Code - the Parameter value is first item in the Code.

e.g.

5 meta [IsParameterQuery=true, Type="Number", IsParameterQueryRequired=true]

5 is the Parameter Value.

To edit, use the "Formula" Property e.g.

ThisWorkbook.Queries("ParameterName").Formula = 'New code here
Sign up to request clarification or add additional context in comments.

3 Comments

How do you run the query? Do a Refresh? Can you share more M code so I can see where you added the meta?
The meta is the first line i.e. for a parameter, the M code I posted above is all there is. Refresh other queries that depend on the parameter.
Thanks! In principle it works great, but I would just add that the correct syntax in my case is: ThisWorkbook.Queries.Item("name_of_the_parameter").Formula = "new_formula_goes_here"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.