Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Power Query NOT Refreshing on Refresh All VBA

I have built a large report using purely Excel with Power Query. A lot of steps are involved in PQ and later loaded in Excel sheet the final report. I tried to automate it but Refreshing is not working and it's a real headache!

The Excel file is a .xlsm (macro enabled).

 

-I have disabled "Background refresh" and tried using the following code. I used the following code and did not work:

 

Public Sub Workbook_Open()

   Application.ScreenUpdating = False

   ActiveWorkbook.RefreshAll

   ThisWorkbook.Save

   Application.Quit

End Sub

 

Still didn't work, it starts refreshing but in reality it doesn't refresh or crashes. When I do manually Refresh All then it works or by pressing refresh icon next to the PQ loaded table.

 

Later I added one line of code being modified to the following:

Public Sub Workbook_Open()

   Application.ScreenUpdating = False

   ActiveWorkbook.RefreshAll

    ActiveWorkbook.Connections("Query - Final result").Refresh  { Added this line}

   ThisWorkbook.Save

   Application.Quit

End Sub

 

It still doesn't work. I don't know what I have to do to solve this! I have requested PowerBI Pro version but I am not sure if there is automatic schedueling to solve this.

 

Any help is appreciated.

 

 

 

5 REPLIES 5
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

Did you find a solution finally? Could you share it here if you have got one?

 

Best Regards,
Community Support Team _ Jing

Anonymous
Not applicable

//You've got to give the workbook time to refresh. I always add an

Application.OnTime(NOW + "00:05:00", ThisWorkBook.NameOfCloseModule)

//and then make a separate module (NameOfCloseModule) that you can //put your ThisWorkbookSave and ActiveWorkbook.Close procedures.

Now it won't try to save then close for 5 minutes, or however long you want.

 

--Nate

 

 

 

 

CNENFRNL
Community Champion
Community Champion

Sounds wierd. It functions well on my end.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

@CNENFRNL I will have a check with your code. Just a quick question, I saw your VBA code, could you clafify what I wrote in purple below?

 

Public Sub Workbook_Open()
Application.ScreenUpdating = False
' ActiveWorkbook.RefreshAll

With ActiveWorkbook.Connections("Query - Query1")
.Refresh
.OLEDBConnection.BackgroundQuery = bBackground //bBackground or Background only?
End With

ThisWorkbook.Save

' Application.Quit
End Sub

 

 

wdx223_Daniel
Community Champion
Community Champion

you need save file after the refresh is completed. unfortunately, I have not heard of the method to get the query refreshing status with VBA.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.