title: VBA Excel - Refresh Pivot Table/Power Query
body: <p>I'm trying to refresh a Power Query &amp; then a Pivot Table (running off that data) &amp; I can get it to work when I step through the code using F8 but it will not work when running the macro</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks!!</p>
  
  <pre><code>Sub Test()
  
  Dim WB As Workbook
  Dim pt As PivotTable
  Set WB = ThisWorkbook
  Set pt = ActiveSheet.PivotTables("PivotTable1")
  
  'Refresh Power Queries &amp; Pivot Tables
  ThisWorkbook.RefreshAll
  WB.Worksheets("By Customer Pivot").Activate
  pt.RefreshTable
  
  
  End Sub
  
  </code></pre>