Hello to all,
The code below works great for listing all the files of a specific folder, but the moment I try to modify it I get in trouble. I would like the macro NOT to generate a new folder but always use the same folder plus I don't want that first line in cell A1 saying "The files found in..."
This is my first experience with Excel 2007 and it's becoming very painfull. Thank you all for your help!
********************************************
Sub ListAllFile()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets.Add
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder("C:\")
ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & "are:"
'Loop through the Files collection
For Each objFile In objFolder.Files
ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
Next
'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
The code below works great for listing all the files of a specific folder, but the moment I try to modify it I get in trouble. I would like the macro NOT to generate a new folder but always use the same folder plus I don't want that first line in cell A1 saying "The files found in..."
This is my first experience with Excel 2007 and it's becoming very painfull. Thank you all for your help!
********************************************
Sub ListAllFile()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets.Add
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder("C:\")
ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & "are:"
'Loop through the Files collection
For Each objFile In objFolder.Files
ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
Next
'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub