No Application.Filesearch in 2007
In earlier versions Application.FileSearch could be used to loop through all
the files contained in a Directory. This does not appear to work in 2007
versions. I have managed to use Dir to achieve this instead
' DateTime : 09/05/2007 08:43
' Author : Roy Cox (royUK)'
' Purpose : Open all worksheets in a specific folder' Disclaimer; This code is
offered as is with no guarantees. You may use it in your' projects but please
leave this header intact.
'---------------------------------------------------------------------------------------
Option Explicit
Sub Open_All_Files()
Dim oWbk As Workbook
Dim sFil As String
Dim sPath As String
sPath = "C:\Documents and Settings\Roy Cox\My Documents\" 'location of files
ChDir sPath
sFil = Dir("*.xlsx") 'change or add formats
Do While sFil <> "" 'will start LOOP until all files in folder sPath have been
looped through Set oWbk = Workbooks.Open(sPath & "\" & sFil) 'opens the file
' do something
oWbk.Close True 'close the workbook, saving changes
sFil = Dir
Loop ' End of LOOP
End Sub
Note: all our examples are offered as is with no warranty. J & R Excel Solutions accept no responsibility for any loss arising from your use of them
