Hi!
I want to pick all names of files with different extensions in one excel sheet. Those files are in same folder with my Excel file. How can i do this? Please help me!
Thanks in advance
SureshP
Hi!
I want to pick all names of files with different extensions in one excel sheet. Those files are in same folder with my Excel file. How can i do this? Please help me!
Thanks in advance
SureshP
Have a look at the Dir function in VBA help.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Hi!
I am very new to VBA, so it will be more helpful to me if you give me one example.
Thanks
[vba]
Public Sub Test()
Dim sFile As String
Dim i As Long
i = 1
sFile = Dir("C:\Projects\Temp\*.*") '<=== change to suit
Do While sFile <> ""
Cells(i, "A").Value = sFile
On Error Resume Next
sFile = Dir
On Error GoTo 0
i = i + 1
Loop
End Sub
[/vba]
Same things as dir, using fso.
[VBA]
Dim FSO As object, f As object, Path As String
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each f In FSO.GetFolder("C:\").Files
ActiveSheet.Range("a" & Application.Rows.Count).End(xlUp).Offset(1, 0) = f.Name
Next f
[/VBA]
Although my code is getting far more files for some reason? Maybe I'm picking up hidden and system files as well? Not sure.
If files are hidden, and a directory listing is set to not show system files, it could be argued that they shouldn't be picked up, after all it is either company or user policy.
Nor me, just ruminating out aloud.
Hi!
Thanks to Bob and Cal and all who helped me to do this! thankyou very much