AT_TreeFortConsulting
New Member
- Joined
- Aug 3, 2021
- Messages
- 14
- Office Version
- 2016
- Platform
- Windows
I'm looking for a way to use the "refresh all" ribbon button to update my power query that's in a protected sheet. I found code that works when opening the workbook, but am getting an error when trying to refresh all in the protected sheet.
The worksheet name is "Daily Activity"
The query name in the protected sheet is "daily_activity_detailed_AEI_all"
Goal: When pressing "refresh all" button in ribbon under the data tab:
Current VBA code (in workbook module) for both the "refresh all" and for when I open the workbook (the open workbook is working correctly):
The worksheet name is "Daily Activity"
The query name in the protected sheet is "daily_activity_detailed_AEI_all"
Goal: When pressing "refresh all" button in ribbon under the data tab:
- Daily Activity sheet is unprotected
- All connections are refreshed
- Daily Activity sheet is protected again
Current VBA code (in workbook module) for both the "refresh all" and for when I open the workbook (the open workbook is working correctly):
VBA Code:
Option Explicit
Private WithEvents QT As QueryTable
Private Sub QT_AfterRefresh(ByVal Success As Boolean)
If Success Then
Sheets("Daily Activity").Unprotect
ActiveWorkbook.Connections("Query - daily_activity_detailed_AEI_all").Refresh
End If
End Sub
Private Sub Workbook_Open()
Sheets("Daily Activity").Unprotect
ActiveWorkbook.Connections("Query - daily_activity_detailed_AEI_all").Refresh
Sheets("Daily Activity").Protect
End Sub