Good afternoon!
I have this VBA code that sometimes gives me a Run-time error '1004', but not everytime. When I click Debug the first item under "With pf" is highlighted, but I don't know how to fix. Can anyone help?

If it helps, I got this code from: http://www.contextures.com/xlPivot12.html#Restrict

Sub RestrictPivotTable()
Dim pf As PivotField
With ActiveSheet.PivotTables(1)
  .EnableWizard = False
  .EnableDrilldown = False
  .EnableFieldList = False
  .EnableFieldDialog = False
  .PivotCache.EnableRefresh = False
  For Each pf In .PivotFields
    With pf
      .DragToPage = False
      .DragToRow = False
      .DragToColumn = False
      .DragToData = False
      .DragToHide = False
    End With
  Next pf
End With

End Sub
As always, many thanks for your help!
N