R
rob nobel
I have the following code run on opening the file, but it says, "Cannot edit
pivot table on protected sheet. That dialog box comes up twice, immediately
after each other. After clicking OK, the file opens still having done the
full procedure!??
The strange thing is that if I execute the code via VBA editor it works
perfectly without the messages.
I can't see what the problem is. Please help
When I open VBA editor immediately after this, it always opens at another
worksheet module ("Sheet9"), that only has this code in it.
Sub RefreshPivot()
Call ThisWorkbook.UpdateAllPivotTables
End Sub
The "ThisWorkbook" code is as follows:
Private Sub Workbook_Open()
Call UpdateAllPivotTables
'Application.ScreenUpdating = False
With Sheets("ALL A-C")
.EnableAutoFilter = True
..Protect Password:="", UserInterfaceOnly:=True
End With
'Application.ScreenUpdating = True
End Sub
Sub UpdateAllPivotTables()
'Debra Dalgleish's gets rid of unused items in PivotTable
' AND update pivot tabel (based on MSKB Q202232)
Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim i As Integer 'I don't think this dim is required.
'Application.ScreenUpdating = False
With Sheet5
..Unprotect Password:=""
End With
With Sheet6
..Unprotect Password:=""
End With
With Sheet9
..Unprotect Password:=""
End With
'Application.ScreenUpdating = False
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
For Each pf In pt.PivotFields
For Each pi In pf.PivotItems
If pi.RecordCount = 0 And _
Not pi.IsCalculated Then
pi.Delete
End If
Next
Next
Next
Next
With Sheet5
..Protect Password:="", UserInterfaceOnly:=True
End With
With Sheet6
..Protect Password:="", UserInterfaceOnly:=True
End With
With Sheet9
..Protect Password:="", UserInterfaceOnly:=True
End With
Application.ScreenUpdating = True
End Sub
Thankyou for any help,
Rob
pivot table on protected sheet. That dialog box comes up twice, immediately
after each other. After clicking OK, the file opens still having done the
full procedure!??
The strange thing is that if I execute the code via VBA editor it works
perfectly without the messages.
I can't see what the problem is. Please help
When I open VBA editor immediately after this, it always opens at another
worksheet module ("Sheet9"), that only has this code in it.
Sub RefreshPivot()
Call ThisWorkbook.UpdateAllPivotTables
End Sub
The "ThisWorkbook" code is as follows:
Private Sub Workbook_Open()
Call UpdateAllPivotTables
'Application.ScreenUpdating = False
With Sheets("ALL A-C")
.EnableAutoFilter = True
..Protect Password:="", UserInterfaceOnly:=True
End With
'Application.ScreenUpdating = True
End Sub
Sub UpdateAllPivotTables()
'Debra Dalgleish's gets rid of unused items in PivotTable
' AND update pivot tabel (based on MSKB Q202232)
Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim i As Integer 'I don't think this dim is required.
'Application.ScreenUpdating = False
With Sheet5
..Unprotect Password:=""
End With
With Sheet6
..Unprotect Password:=""
End With
With Sheet9
..Unprotect Password:=""
End With
'Application.ScreenUpdating = False
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
For Each pf In pt.PivotFields
For Each pi In pf.PivotItems
If pi.RecordCount = 0 And _
Not pi.IsCalculated Then
pi.Delete
End If
Next
Next
Next
Next
With Sheet5
..Protect Password:="", UserInterfaceOnly:=True
End With
With Sheet6
..Protect Password:="", UserInterfaceOnly:=True
End With
With Sheet9
..Protect Password:="", UserInterfaceOnly:=True
End With
Application.ScreenUpdating = True
End Sub
Thankyou for any help,
Rob