2

Good day

I am looking for a way to pass a username and API key to PowerQuery from registry information via VBA. I don't want the information to necessarily be contained in a cell on a sheet because I would like to restrict functionality to a user's PC.

Any thoughts on how I can pass the variable / parameter from the registry or from a VBA variable to PowerQuery?

As a POC, I do currently have the information in a hidden cell on a sheet and PowerQuery reads it with:

= Excel.CurrentWorkbook(){[Name="username"]}[Content]{0}[Column1]

Much appreciated.

1 Answer 1

1

I've figured it out from another thread here: https://hatfullofdata.blog/excel-power-query-vba-to-edit-a-parameter-value/

Option Explicit

Sub ChangeParameterValue(ParameterName As String, ParameterValue As String)

    Dim qry As WorkbookQuery
    Dim formula As Variant
    
    '=== Get the query
    Set qry = ThisWorkbook.Queries(ParameterName)
    
    '=== Split the formula into 3 parts and update the second one
    formula = Split(qry.formula, Chr(34), 3)
    formula(1) = ParameterValue
    
    '=== Update the parameter value
    qry.formula = Join(formula, Chr(34))
    
End Sub

Sub MySub()
    ChangeParameterValue "username", "[email protected]"
    ChangeParameterValue "api_key", "adfsd32564fdsfdsf8rr46we5"
End Sub
Sign up to request clarification or add additional context in comments.

Comments

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.