title: Excel vba: error hiding calculated field in Pivot table
body: <p>I have written several Subs to show/hide fields in a PivotTable.
  Now I am trying to do the same with a calculated field, but I get an error when hiding it.
  I took my code from the recorder and the recorder's code also halts on the last line.
  I googled the error message, without serious result.</p>
  
  <pre><code>Sub PrRemove()
      'remove PR
      Dim pt As PivotTable
      Set pt = ActiveSheet.PivotTables("MyPivot")
      pt.PivotFields("MyField").Orientation = xlHidden   '&lt;- here is the error
  End Sub
  </code></pre>
  
  <p>The same code works fine if MyField is a normal field (not a calculated one).<br>
  I am using Excel 2007 with SP2.<br>
  Any clue ?</p>
  
  <p><strong>EDIT on 17 June 2010</strong>: I also tried using pt.DataFields instead of pt.PivotFields, with exactly the same behaviour.  The error message says "Unable to set the orientation of the PivotField class".</p>