title: Refreshing an Excel Pivot table from C#
body: <p>I am trying to refresh a pivot table in an Excel sheet and get the following exception:</p>
  
  <pre><code>Item method in the PivotTables class failed
  </code></pre>
  
  <p>Heres the code:</p>
  
  <pre><code>pivotSheet.Activate();
  Microsoft.Office.Interop.Excel.PivotTables pivotTables = 
          (Microsoft.Office.Interop.Excel.PivotTables)pivotSheet.PivotTables(missing);
  int pivotTablesCount = pivotTables.Count;  
      if (pivotTablesCount &gt; 0)
      {
          for (int i = 0; i &lt;= pivotTablesCount; i++)
          {
              pivotTables.Item(i).RefreshTable(); //The Item method throws an exception
          }
      }
  </code></pre>
  
  <p>Any idea?</p>