Excel pivot refresh, save and close in Access VBA code

Posted by schneidm on Stack Overflow See other posts from Stack Overflow or by schneidm
Published on 2010-01-15T03:47:08Z Indexed on 2010/06/09 1:02 UTC
Read the original article Hit count: 230

Filed under:
|

I am using the following code to refresh Excel pivot tables from an Access application. What is the best way to save and close the Excel app after the pivots refresh? In my last attempt the code was trying to save and close before the pivots had refreshed.

Private Sub Command161_Click()   
  Dim objXL As Object, x

  On Error Resume Next
  Set objXL = CreateObject("Excel.Application")
  With objXL.Application
    .Visible = True
    'Open the Workbook
    .Workbooks.Open "myfilepath.xls"
    'Refresh Pivots
    x = .ActiveWorkbook.RefreshAll
  End With    
  Set objXL = Nothing
End Sub

© Stack Overflow or respective owner

Related posts about ms-access

Related posts about access-vba