-
In excel I am needing to open all the files in a specified folder called TLResults that is on the C:drive. and also list all these file names in a range on sheet 1 starting on cell A1 on the excel document that I am useing when I start the macro.
I have been looking at the code on other posts but it doesnt seen to translate to excel vba, or at least not to me.
Any help on how to write this would be greatly appreciated.
Douglas
-
Here's a Excel VBA macro that will do just that:
Code:
Sub OpenAllFiles()
Dim sFile As String
Dim wrkBook As Workbook
Dim iCount%
Const sPath As String = "c:\TLResults\"
Set wrkBook = ActiveWorkbook
sFile = Dir(sPath & "*.xls")
Do While Len(sFile)
iCount = iCount + 1
Workbooks.Open sPath & sFile
wrkBook.Activate
wrkBook.Sheets(1).Activate
Range("A" & iCount).Value = sPath & sFile
sFile = Dir
Loop
End Sub
Good luck!