Refreshing table query on a protected sheet

karolina1406

Board Regular
Joined
Apr 18, 2016
Messages
108
Office Version
  1. 365
Platform
  1. Windows
I am refreshing the table query on a protected sheet. I use below code that works fine however, as soon as I add one more command to protect sheets back - i get Run time error 91: object variable or With block variable not set

VBA Code:
Dim wSheet As Worksheet
For Each wSheet In Worksheets
wSheet.Unprotect Password:="password"
Next wSheet
Application.ScreenUpdating = False
Sheets("Available_Stock").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False

Any ideas why??
 

Some videos you may like

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Watch MrExcel Video

Forum statistics

Threads
1,114,069
Messages
5,545,803
Members
410,708
Latest member
SanTrapGamer
Top