import list of filenames

ruick

New Member
Joined
Dec 18, 2009
Messages
4
Hey everyone,

I have a list of pictures in a folder and i want the urls of the pictures to be inputted into a column. I searched the forums and the closest thing i found was this:

Code:
 Dim fs As FileSearch, i As Long    
    Set fs = Application.FileSearch    
    With fs    
        .SearchSubFolders = False
        .FileType = msoFileTypeWebPages
        .LookIn = "C:\Documents and Settings\sandeepw\Desktop\"
        If .Execute > 0 Then        
            For i = 1 To .FoundFiles.Count            
                Cells(i + 1, 60) = .FoundFiles(i)                
            Next i        
        End If        
    End With</pre>

Now i know msofiletypewebpages = what should that be changed to for pictures? Anyway i tried to test this with some html files and when i ran the macro it didnt do anything?

This is exactly what i had:

Code:
Sub MyMacro()
Dim fs As FileSearch, i As Long
    Set fs = Application.FileSearch
    With fs
        .SearchSubFolders = False
        .FileType = msoFileTypeWebPages
        .LookIn = "C:\Documents and Settings\user\Desktop\f\"
        If .Execute > 0 Then
            For i = 1 To .FoundFiles.Count
                Cells(i + 1, 60) = .FoundFiles(i)
            Next i
        End If
    End With
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
One thing for sure - If you are running xl 2007...

Application.FileSearch ** NO LONG EXISTS**

It exists only in 2003 and prior..
 
Upvote 0
This is how I would do it, compatible with 2007 or 2003:
Rich (BB code):
Sub ListFiles()
Dim fName As String, fPath As String, i As Long

fPath = "C:\Documents and Settings\user\Desktop\f\"
fName = Dir(fPath & "*.html")  'first filename
i = 1
    
    Do While Len(fs) > 0
        Cells(i + 1, 6) = fs
        i = i + 1
        fName = Dir            'next filename
    Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top