Excel VBA command to run Power Query

kaz123

New Member
Joined
Oct 8, 2017
Messages
14
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
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

sandy666

Banned - Rules violations
Joined
Oct 24, 2015
Messages
7,499
fortunately Power Query doesn't support vba in any way
 

rjmdc

Active Member
Joined
Apr 29, 2020
Messages
375
Office Version
  1. 365
Platform
  1. Windows
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
 

kaz123

New Member
Joined
Oct 8, 2017
Messages
14
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,472
Messages
5,596,353
Members
414,060
Latest member
hermanseck

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
Top