I have workbook which contains many vba codes, many pivot tables in different worksheets and more than 100 worksheets. My problem is that
1. if I protect all the worksheets in workbook_open event:
Private Sub Workbook_Open()
Dim wSheet As Worksheet
For Each wSheet In Worksheets
wSheet.Protect Password:="khatkar", UserInterfaceOnly:=True
Next wSheet
End Sub
And try to refresh my pivot table reports with this code:
Private Sub Worksheet_Activate()
Dim pt As PivotTable
For Each pt In Me.PivotTables
pt.RefreshTable
Next pt
End Sub
Then it shows "Run-time error 1004: RefreshTable method of PivotTable class failed".
2. But if I protect sheets using this code:
Private Sub Workbook_Open()
Dim ws As Worksheet
Set WSArray = Sheets(Array("MASTERWORK", "PENDDATA", "PENDRPT_VILLWISE"))
For Each ws In WSArray
ws.Protect password:="khatkar", UserInterfaceOnly:=True
Next
End Sub
And try to update pivot table with the second (above) code, it works fine.
I can't use the second Protection code because workbook contains more than 100 sheets and I will take a long time type the names of all the sheets in the code.
Please help me why even after setting "userinterfaceonly" to true in the first protection code, my pivot table are updating. Please help me out.
1. if I protect all the worksheets in workbook_open event:
Private Sub Workbook_Open()
Dim wSheet As Worksheet
For Each wSheet In Worksheets
wSheet.Protect Password:="khatkar", UserInterfaceOnly:=True
Next wSheet
End Sub
And try to refresh my pivot table reports with this code:
Private Sub Worksheet_Activate()
Dim pt As PivotTable
For Each pt In Me.PivotTables
pt.RefreshTable
Next pt
End Sub
Then it shows "Run-time error 1004: RefreshTable method of PivotTable class failed".
2. But if I protect sheets using this code:
Private Sub Workbook_Open()
Dim ws As Worksheet
Set WSArray = Sheets(Array("MASTERWORK", "PENDDATA", "PENDRPT_VILLWISE"))
For Each ws In WSArray
ws.Protect password:="khatkar", UserInterfaceOnly:=True
Next
End Sub
And try to update pivot table with the second (above) code, it works fine.
I can't use the second Protection code because workbook contains more than 100 sheets and I will take a long time type the names of all the sheets in the code.
Please help me why even after setting "userinterfaceonly" to true in the first protection code, my pivot table are updating. Please help me out.