I currently have this code which will take files from a folder, open one each one, print its name into the first column of my "Master file" close it and loop through the entire folder that way.
In each file that is opened, there is information in cell J1 that I would like to copy and paste into column 3 of my "master file". The section of code currently returns an error (Object does not support this property or method but I cannot tell which line it is referring to) and causes the program to stop after only opening one file.
Any ideas?
FULL CODE:
Sub LoopThroughDirectory()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim MyFolder As String
Dim Sht As Worksheet
Dim i As Integer
MyFolder = "C:\Users\trembos\Documents\TDS\progress\"
Set Sht = ActiveSheet
'create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'get the folder object
Set objFolder = objFSO.GetFolder(MyFolder)
i = 1
'loop through directory file and print names
For Each objFile In objFolder.Files
If LCase(Right(objFile.Name, 3)) <> "xls" And LCase(Left(Right(objFile.Name, 4), 3)) <> "xls" Then
Else
'print file name
Sht.Cells(i + 1, 1) = objFile.Name
i = i + 1
Workbooks.Open Filename:=MyFolder & objFile.Name
End If
'Get TDS name of open file
Range("J1").Select
Selection.Copy
Windows("masterfile.xlsm").Activate
Range("C2").Select
ActiveSheet.Paste
objFile.Activate
ActiveWorkbook.Close
Next objFile
End Sub
Part of code that is messing up the program:
'Get TDS name of open file
Range("J1").Select
Selection.Copy
Windows("masterfile.xlsm").Activate
Range("C2").Select
ActiveSheet.Paste
objFile.Activate