Update queries in to a protected sheet.

g3org

Board Regular
Joined
Jul 25, 2021
Messages
69
Office Version
  1. 365
Platform
  1. Windows
Hello everyone.
It is possible to update a queries in to a protected sheet automatically or it is just a myth?


Sub RefreshmyQuery()
Sheets("mySheet").Unprotect Password:="myPassword"
ActiveWorkbook.Connections("Query - myQuery").Refresh
Sheets("mySheet").Protect Password:="myPassword"
End Sub

I have tried this way but I still got the error that the sheet is protected. And what I wanna to be automatically refreshed after 2 hours, or when I open the file? Any idea will be helpful!

Thank you.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
You will need to unprotect and reprotect as you are doing but if it is not working then in addition to that try turning off Background refresh.

The link below will tell you how to do that:
 
Upvote 0
That is working, if I run the Macro manually, with this code should not be running automatically when I open the file?

Private Sub Workbook_Open()
Sub RefreshmyQuery()
Sheets("Admin").Unprotect Password:="123"
ActiveWorkbook.Connections("Query - Admin").Refresh
Sheets("Admin").Protect Password:="123"

End Sub
End Sub



Thank you.
 
Upvote 0

Forum statistics

Threads
1,215,123
Messages
6,123,183
Members
449,090
Latest member
bes000

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