title: Excel 2013 - VBA AddDataFiled 1004 Error
body: <p>strange one this</p>
  
  <p>I have a pivot table connected to a data source via power pivot / OLAP.
  I have created a vba button to add a field to the row section of the pivot however when I run...</p>
  
  <pre><code>With ActiveSheet.PivotTables("PivotTable1")
   .AddDataField ActiveSheet.PivotTables( _
   "PivotTable1").CubeFields("[Measures].[Sum of Unique_Customers]"), "Unique Customers"
  End With
  </code></pre>
  
  <p>I get the object error 1004 runtime error 1004 application-defined or object-defined error. </p>
  
  <p>However if I refresh the pivot / data connection then it works fine. I have put in place a workaround to refresh the pivot each time the workbook opens but I fear as my data grows this will become resource heavy. Does anyone know of a solution or a reason to why the error occurs? It seems vb does not recognise the field until the data is refreshed. For info the field is a raw field and not a MDX calc or anything</p>
  
  <p>Many thanks!</p>