Open, refresh, close multiple excel documents

MPFraser7

New Member
Joined
Dec 14, 2016
Messages
34
I have a folder with many documents, excel, word, outlook e-mails, etc. I'm looking for a macro that would open, refresh and close all Excel documents where the name starts with "FI". There are many sheets, tables, pivottables, connections, etc. found inside the excel documents. Is there an easy way to do so? Thanks for your time, much appreciated.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi, this may work, credit to AndyG on stackoverflow for some help here: https://stackoverflow.com/questions/19527415/using-a-wildcard-to-open-an-excel-workbook

Code:
Sub refreshAll()

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Dim sFound As String


sFound = Dir(ActiveWorkbook.Path & "\FI*.xlsx")    'the first one found, change .xlsx to whatever kind of excel files they are, assumes the other excel files are in same path as current open one
If sFound <> "" Then
    Workbooks.Open filename:= ActiveWorkbook.Path & "\" & sFound

End If

Dim i As Integer
Dim wc As Integer
wc = Workbooks.Count

For i = 1 To wc
    Workbooks(i).RefreshAll
    Workbooks(i).Close True
Next

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0
Thanks for your help. I stored the macro in a blank excel document in the same folder as the other documents starting with "FI". When I run the macro, it closes the macro document, opens the first document starting with "FI" and then it completely stops. It does not refresh, close, and repeat the process with the next document. Any ideas?
 
Upvote 0

Forum statistics

Threads
1,226,114
Messages
6,189,051
Members
453,522
Latest member
Seeker2025

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top