Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

VBA procedure to pen an Excel workbook and refresh all datas in the QueryTables and PivotTable objects (See related posts)

// description of your code here
// Can also use the Workbook Open event ( Private Sub Workbook_Open() )

Sub Auto_Open()
Application.DisplayAlerts = False
    ChDir "T:\EXPLOIT\TSMENV\EXCEL\politiques"
    Workbooks.Open Filename:="t:\EXPLOIT\TSMENV\EXCEL\politiques\politiques.xls", _
        UpdateLinks:=3
    For i = 1 To ActiveWorkbook.PivotCaches.Count
        ActiveWorkbook.PivotCaches(i).RefreshOnFileOpen = False
    Next
    For i = 1 To ActiveWorkbook.Sheets.Count
        For j = 1 To ActiveWorkbook.Sheets(i).QueryTables.Count
            ActiveWorkbook.Sheets(i).QueryTables(j).RefreshOnFileOpen = False
        Next
    Next
    ActiveWorkbook.RefreshAll
    ActiveWorkbook.RefreshAll
    ActiveWorkbook.RefreshAll
    ActiveWorkbook.Save
    ActiveWindow.Close
    Application.Quit
End Sub

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts