XL2007 problem with Macro

scoha

Active Member
Joined
Jun 15, 2005
Messages
428
I have a great macro which gets all the file names from a nominated directory and after I recently upgraded to 2007 it doesnt work - returns a Object Doesnt Support This Action error.

Here is my code:

Code:
Sub ListJpgFiles()
    ' This macro lists all .jpg files
    ' in a certain directory to a column in Excel
    Range("A1").Value = "FileName"
    NextRow = 2
    ' Use the FileSearch Object
    With Application.FileSearch
        .NewSearch
        ' Customize the following line
        .LookIn = "G:\Facilities\Towers\TwrPics\ "
        .SearchSubFolders = True
        .Filename = "*.jpg"
        .Execute
        FilesToProcess = .FoundFiles.Count
        ' loop through each workbook in the directory
        For i = 1 To .FoundFiles.Count
            ThisEntry = .FoundFiles(i)
            ' Find to path portion. Start looking from the end
            ' of This Entry for a backslash
            For j = Len(ThisEntry) To 1 Step -1
                If Mid(ThisEntry, j, 1) = Application.PathSeparator Then
                    Cells(NextRow, 1) = Mid(ThisEntry, j + 1)
                    Exit For
                End If
            Next j
            NextRow = NextRow + 1
        Next i
    End With
End Sub


Must be something to do with the File Search object??
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
this works for me in 2007



Sub Showfiles()

Dim fs, SEARCHAREA, ITEM, RESULTS
Set fs = CreateObject("Scripting.fileSystemObject")
Set SEARCHAREA = fs.Getfolder("c:\test")
Set RESULTS = SEARCHAREA.Files

For Each ITEM In RESULTS
Range("a" & Range("a5000").End(xlUp).Row + 1).Value = ITEM.Name
Next

End Sub

hope this helps.
 
Upvote 0

Forum statistics

Threads
1,215,706
Messages
6,126,336
Members
449,310
Latest member
zztt388

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