I have 6 Excel files in "Final Folder". I need to open each in turn, put in some data from the workbook where code is running (I am using ThisWorkbook for source).
The code opens all 6 files together rather than opening them in turn.
It seems when running Workbooks.Open
within the loop, all the files open by default.
Sub PopulateFinalFile()
Dim filpath As String
Dim fso As Scripting.FileSystemObject
Dim fil As Scripting.File
Dim fldr As Scripting.Folder
filpath = "C:\Users\deepak.ved\Desktop\Reports\Final Reports"
Set fso = New Scripting.FileSystemObject
Set fldr = fso.GetFolder(filpath)
For Each fil In fldr.Files
Application.Workbooks.Open (fso.GetFile(fil.Path))
Next fil
End Sub
Unrelated question: How can I point to a workbook using FSO. Like if I use getfile
or folder.files
, it returns a path. When I am passing the path to a workbook, I need to have workbook.open(path)
but all I want is to point to that workbook instead of opening it.