FileSystemObject Run-Time error 13 Type Mismatch

You get a Type Mismatch Error on the GetFolder line!! Why is that? Because the Folder declaration needs to be like this: Dim oFolder As Scripting.Folder. This will be the case even if you have a reference to Microsoft Scripting Runtime.

The code below will fail. Add the Scripting. to the Folder declarion and it will work!

Dim oFileSystem As New FileSystemObject
Dim oFolder As Folder
Dim oCurrentFile As File
Dim oFileColl As Files

Set oFolder = oFileSystem.GetFolder("d:\data\bradfb\Desktop\CR Disposition\")
Set oFileColl = oFolder.Files

If oFileColl.Count > 0 Then
    With lstFiles
        For Each oCurrentFile In oFileColl        
            .AddItem oCurrentFile.Name            
        Next        
        .ListIndex = 0        
    End With
   
End If

Set oFileSystem = Nothing
Set oFolder = Nothing
Set oFileColl = Nothing

Add comment

Loading