Bulk refreshing workbooks
Workbooks that pull data through Power Query go stale until someone refreshes them. There are a few ways to refresh them on a schedule:
- publish the reports to Power BI
- let SharePoint refresh the workbooks
- use a desktop tool that opens and refreshes each workbook in turn
The drawbacks of Power BI and SharePoint
Section titled “The drawbacks of Power BI and SharePoint”Power BI refreshes reports on a schedule, but everyone who views a shared report normally needs a paid licence, which adds up across a team. SharePoint works if the organisation has it set up to refresh workbooks and the files are meant to be shared there, but many people have no access to it, or need to send the refreshed files out in other ways. That leaves the third option, a desktop tool, which this page describes.
Bulk workbook refreshing
Section titled “Bulk workbook refreshing”1. How the refresh works
Section titled “1. How the refresh works”The tool is semi-automatic, because someone has to start it. A run has three steps:
- Open the refresh tool workbook.
- Mark the folders to refresh.
- Click the refresh button.
The tool then works through each file in the marked folders in turn, opening it, refreshing it, saving it and closing it. When it finishes, it lists which workbooks were refreshed and how long each one took.
2. Prepare the folders
Section titled “2. Prepare the folders”- Create an empty folder to hold the workbooks. It can be on a shared network drive or on the local PC, beside the refresh tool.
- Inside it, create a subfolder for each group of workbooks that is refreshed on its own cycle. The example uses refresh frequencies, but any grouping that suits the business will do.

Then move each workbook into the right subfolder.
3. Set up the refresh tool
Section titled “3. Set up the refresh tool”- Open the tool and fill in the setup cells so that they point to the main folder. The full path of the folder goes in cell J1, and a file pattern, such as
*.xlsx, goes in cell J2 if only some files should be refreshed.

- Click Update File List. The table on the left fills with each subfolder and the files in it, as in the example below. Column C is hidden, and holds each file’s full path.

- Type a frequency, such as Daily, Weekly or Monthly, against each file in the Refresh Frequency column. This is needed only once, when the tool is set up.
- Files can also be added to the list by hand, as long as their full path is entered in column C.
4. Run the tool
Section titled “4. Run the tool”To refresh the workbooks:
- Open the refresh tool.
- In the table on the right, put an x against each folder to refresh.
- Click Refresh Selected Reports, and leave it to run.
5. VBA code
Section titled “5. VBA code”The macros behind the tool’s buttons are listed below.
Sub RefreshAll() RefreshFilesEnd SubSub UpdateFileList() ListAllFolders FileListerEnd SubSub FileLister() Dim X As String Dim myDir As String Dim Y As Integer Dim myFileSystem As Object Dim myFileObject As Object Dim myFreq As Variant Dim myPattern As String Application.ScreenUpdating = False
Set myFileSystem = CreateObject("Scripting.FileSystemObject")
Sheets("files").Activate Range("B1").CurrentRegion.Offset(1, 0).Clear Range("B2").Select myPattern = Range("Pattern").Value
Sheets("folders").Activate Range("b6").Select
On Error GoTo FolderError While Selection.Value <> "" myDir = Selection.Value myFile = myDir & myPattern Sheets("files").Activate X = Dir(myFile, 2) Do Until X = "" myFreq = Split(myDir, "\") Selection.Value = myFreq(UBound(myFreq) - 1) Selection.Offset(0, 1).Value = myDir Selection.Offset(0, 2).Value = X Set myFileObject = myFileSystem.Getfile(myDir & X) Selection.Offset(0, 3).Value = myFileObject.Size Selection.Offset(0, 3).NumberFormat = "#,##0" Selection.Offset(0, 4).Value = myFileObject.DateLastModified Selection.Offset(1, 0).Select X = Dir LoopnoFiles: Sheets("folders").Activate Selection.Offset(1, 0).Select WendExitHere:On Error GoTo 0Set myFileSystem = NothingSet myFileObject = NothingSheets("files").ActivateApplication.ScreenUpdating = TrueExit SubFolderError:Resume noFilesEnd SubSub ListAllFolders() Dim X As Integer Dim myDir As String
Application.ScreenUpdating = False myDir = Range("StartFolder").Value
If myDir = "" Then X = MsgBox("Enter a start folder in cell " & Range("startfolder").Address, vbOKOnly) GoTo ExitHere: End If
Sheets("folders").Activate Range("b6").CurrentRegion.Clear
If Right(myDir, 1) <> "\" Then myDir = myDir & "\" Range("b6").Select On Error GoTo Error: ListFolders (myDir) GoTo ExitHere:Error: X = MsgBox("Invalid Folder Name", vbOKOnly)ExitHere: Sheets("files").Activate Range("StartFolder").Value = myDir Application.ScreenUpdating = TrueEnd SubSub ListFolders(myDir) Dim FS, f, f1, fc, s If myDir = Empty Then GoTo ExitHere: Set FS = CreateObject("Scripting.FileSystemObject") Set f = FS.GetFolder(myDir) Set fc = f.SubFolders
For Each f1 In fc Selection.Value = myDir & f1.Name & "\" Selection.Offset(1, 0).Select NextExitHere: Set FS = Nothing Set f = Nothing Set fc = NothingEnd SubSub RefreshFiles() Dim tbRef As Object Dim myFile As String Dim toDo As Collection Dim myStart As Date
Set tbRef = ActiveSheet.ListObjects("table2") Application.DisplayAlerts = False
'create to do list Set toDo = New Collection Intersect(tbRef.ListRows(1).Range, tbRef.ListColumns(1).Range).Select
While Selection <> "" If UCase(Selection.Offset(0, 1)) = "X" Then toDo.Add (Selection.Value) End If Selection.Offset(1, 0).Select Wend
'execute todo list Range("A2").Select
While Selection <> "" For Each Item In toDo If Selection.Value = Item Then myFile = Selection.Offset(0, 2) & Selection.Offset(0, 3) myStart = Now() Workbooks.Open Filename:=myFile Application.DeferAsyncQueries = True ActiveWorkbook.RefreshAll Application.CalculateUntilAsyncQueriesDone Application.DeferAsyncQueries = False DoEvents ActiveWorkbook.Save ActiveWorkbook.Close Selection.Offset(0, 5).Value = Now Selection.Offset(0, 6).Value = "Done" Selection.Offset(0, 7).Value = Now() - myStart Selection.Offset(0, 7).NumberFormat = "hh:mm:ss" Application.Wait Now + TimeValue("00:00:02") End If Next Item Selection.Offset(1, 0).Select
Wend Set toDo = Nothing Set tbRef = Nothing Application.DisplayAlerts = TrueEnd Sub