title: Excel VBA update chart not visible
body: <p>I have an excel file which iterates over different excel files to update them and create a PDF file from them.</p>
  <p>The macro iterates over rows and opens the files. This code opens the files:</p>
  <pre><code>Private Sub openFile(row As Integer)
      Dim filePath As String
      Dim wb As Workbook
  
      filePath = Application.ActiveWorkbook.Path + &quot;\&quot; + allRows(row).filename
      Set wb = Workbooks.Open(filePath)
      Application.Run &quot;RefreshEntireWorksheet&quot;
      
      Application.OnTime Now + (TimeSerial(0, 1, 59)), &quot;'ThisWorkbook.updateCharts &quot;&quot;&quot; &amp; row &amp; &quot;'&quot;
      
      Application.OnTime Now + (TimeSerial(0, 2, 59)), &quot;'ThisWorkbook.createEmail'&quot;
  End Sub
  </code></pre>
  <p>Now if there are multiple files, only 1 file has the charts properly updated (the file being on the front). It seems like the <code>updateCharts</code> code doesn't work at all:</p>
  <pre><code>Sub updateCharts(row As Integer)
      
      Dim SheetName As String
      Dim wb As Workbook
      
      SheetName = &quot;Sheet1&quot;
      With Application
          .ScreenUpdating = True
          .EnableEvents = True
      End With
  
  
      Set wb = Workbooks(allRows(row).filename)
      wb.Activate
      wb.Sheets(SheetName).Activate
      For Each cht In wb.Sheets(SheetName).ChartObjects
          cht.Chart.Refresh
          DoEvents
      Next cht
      
  End Sub
  </code></pre>
  <p>I checked following links for answers, but none helped:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/42113581/cant-refresh-a-chart-in-excel-vba-excel-2016">Can&#39;t refresh a chart in Excel VBA (Excel 2016)</a></li>
  <li><a href="https://stackoverflow.com/questions/28582897/refresh-all-charts-without-blinking">Refresh all charts without blinking</a></li>
  <li><a href="https://stackoverflow.com/questions/51957981/excel-chart-not-updating-when-data-changed-by-vba">excel chart not updating when data changed by vba</a></li>
  <li><a href="https://stackoverflow.com/questions/30964263/excel-2013-vba-refresh-chart-content-after-each-iteration-of-for-loop">Excel 2013 vba refresh chart content after each iteration of For Loop</a></li>
  </ul>
  <p>They all suggest to add an <code>DoEvent</code>, but that doesn't work. <strong>So the question is, how can I update charts in a different workbook via VBA?</strong></p>