Excel VBA command to run Power Query

kaz123

New Member
Joined
Oct 8, 2017
Messages
31
Hi,

I wanted to find out if there is a way to run/invoke a Power Query using Excel VBA. I have a table of data which I then go onto Power Query manually to transform the data in the desired end state but wanted to see if there is a way to run this query in VBA so that when I assign a button to the macro/vba module it will automatically run the Power query. I am trying to create a spreadsheet for end users in which they can press a macro assigned button that will then transform the data using power query and wanted to see if there is away to avoid all the manual steps

Thanks in advance
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
how about something like this? i actually paid a VBA tech to create this for me
it works

VBA Code:
Sub RefreshPQActiveWorkbook()

Dim ActSheet As String
ActSheet = ActiveSheet.Name

ThisWorkbook.Activate

If MsgBox("Do you want to refresh?", vbOKCancel + vbQuestion) = vbOK Then

    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets
        Call WSUnProtect(ws)
    Next ws

       ActiveWorkbook.RefreshAll
    
      
    For Each ws In ActiveWorkbook.Worksheets
        Call WSProtect(ws)
    Next ws
    
    Worksheets(ActSheet).Activate
    
    MsgBox "Refresh complete", vbInformation
End If

       Application.EnableEvents = True

End Sub
 
Upvote 0
how about something like this? i actually paid a VBA tech to create this for me
it works

VBA Code:
Sub RefreshPQActiveWorkbook()

Dim ActSheet As String
ActSheet = ActiveSheet.Name

ThisWorkbook.Activate

If MsgBox("Do you want to refresh?", vbOKCancel + vbQuestion) = vbOK Then

    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets
        Call WSUnProtect(ws)
    Next ws

       ActiveWorkbook.RefreshAll
   
     
    For Each ws In ActiveWorkbook.Worksheets
        Call WSProtect(ws)
    Next ws
   
    Worksheets(ActSheet).Activate
   
    MsgBox "Refresh complete", vbInformation
End If

       Application.EnableEvents = True

End Sub
Thanks, this was helpful
 
Upvote 0

Forum statistics

Threads
1,214,566
Messages
6,120,262
Members
448,953
Latest member
Dutchie_1

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