VBA - List all Files in Folder - Dir() stops part-way through

i_excel

Board Regular
Joined
Jun 4, 2015
Messages
113
Hey

I've got emails in a desktop folder and I'm trying to list their file names in a worksheet. I've written the below code for that purpose but I'm facing a couple of problems:
1. The filenames are truncated: 20080607-MySpace pa#BFD0E4.html appears rather than 20080607-MySpace password request-36629. I understand this may have something to do with working on a mac, so I don't care so much about resolving this issue.
2. The listing stops part-way through so that i'm only getting about 33,000 instead of 38,000 emails listed. This is a problem.

Any help with the above would be greatly appreciated. Again, I note I'm using a mac.

i_excel


Code:
Sub ListEmails()    
    Dim i As Integer: i = 1
    Dim StrFile As String


    StrFile = Dir("Macintosh HD:Users:Name:Desktop:Gmail Data:test:messages:")  '& filenameCriteria)
    StrFile = Dir()
    
    Do While StrFile <> ""
        Cells(i + 1, 1) = i
        Cells(i + 1, 2).Value = StrFile
        StrFile = Dir()
        
    i = i + 1
    Loop


End Sub
 
I have looked at this several times but have not pressed purchase.....just did it on kindle edition...Once I've recovered from a beating from the wife I'll get into it
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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