PDA

View Full Version : Import all files into Excel



DIStudio
03-04-2008, 01:08 PM
I need to import all files from a folder (hundreds) into their own cell in Excel using VBA so that employees may track the progress of the project at real time without having to open the folder where each individual file is saved. Can anyone at least point me in the right direction as far as code is concerned. Thank you!

Bob Phillips
03-04-2008, 02:11 PM
Here is a starter




Dim oFSO

Sub LoopFolders()

Set oFSO = CreateObject("Scripting.FileSystemObject")

selectFiles "c:\MyTest"

Set oFSO = Nothing

End Sub


'---------------------------------------------------------------------------
Sub selectFiles(sPath)
'---------------------------------------------------------------------------
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr

Set Folder = oFSO.GetFolder(sPath)

For Each fldr In Folder.Subfolders
selectFiles fldr.Path
Next fldr

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
'process it
Activeworkbook.Close Savechanges:=False
End If
Next file

End Sub