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
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,480
One thing for sure - If you are running xl 2007...

Application.FileSearch ** NO LONG EXISTS**

It exists only in 2003 and prior..
 

jbeaucaire

Well-known Member
Joined
May 8, 2002
Messages
6,012
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,721
Messages
5,597,752
Members
414,171
Latest member
12Rev79

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
Top