I want to open all of the files in a certain folder and have it print out the names of those files.
I have set up a code that opens the files but I cannot get it to print the name. I have a separate code that will print the name but will only open one file. I'm failing at combining the two together correctly. Any ideas?
Code that opens all Excel files:
‘set path to progress folder Sub OpenFiles() Dim MyFolder As String Dim MyFile As String MyFolder = “C:\Users\trembos\Documents\TDS\progress" MyFile = Dir(MyFolder & "\*.xlsx") Do While MyFile <> "" Workbooks.Open fileName:=MyFolder & "\" & MyFile MyFile = Dir Loop End Sub
Code that prints one file name:
'set path to TDS_Working Sub TDS() Workbooks.Open ("C:\Users\trembos\Documents\TDS\progress") End Sub 'set up dim Sub LoopThroughDirectory() Dim objFSO As Object Dim objFolder As Object Dim objFile As Object Dim i As Integer 'create an instance of the FileSystemObject Set objFSO = CreateObject("Scripting.FileSystemObject") 'get the folder object Set objFolder = objFSO.GetFolder("C:\Users\trembos\Documents\TDS\progress\") i = 1 'loop through directory file and print names For Each objFile In objFolder.Files 'print file name Cells(i + 1, 1) = objFile.Name Next objFile End Sub