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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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