J & R Solutions

"making Excel work for you!"

Search

Latest news

June 01: Halfway through 2007 and finally had time to tidy up our web site. Hope you like the changes and whilst you are here why not check out the Excel products we are offering

May 28: Opened our new Forum for membership. Free help o all our products and your Excel questions

Links:

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