Type Mismatch Error 13

B

Bob Zimski

Why do I get the error? Oddly enough, I can use the commented line for the
debug.print, but when I try to assign to an array it gives the error.

I'm totally confused.

Bob

Dim FName as Variant
Set fs = Workbooks.Application.FileSearch
With fs
.LookIn = "E:\Stott\Inventory"
'.FileType = msoFileTypeExcelWorkbooks
.FileName = "Input??.xls"
.Execute
End With

For i = 1 To fs.FoundFiles.Count
FName(i) = fs.FoundFiles(i)
'Debug.Print fs.FoundFiles(i)
Next i
 
P

Per Jessen

Hi

You need to redim your array after the End With statement:

Redim fName(1 to fs.foundfiles.count)

Hopes this helps.
....
Per
 
B

Bob Zimski

I tried it and it just gave a new error 'Subscript out of range.'
Like I eluded to earlier, if I commented out the line where I try to assign
FName and uncomment the debug.print, the debug print works and shows three
values as expected. While when I try to do the assignment it gives the Type
Mismatch Error 13.

Still a mystery to me.

Bob
 
P

Per Jessen

Hi

This worked for me:

Dim FName As Variant
Set fs = Workbooks.Application.FileSearch
With fs
.LookIn = "E:\Stott\Inventory"
'.FileType = msoFileTypeExcelWorkbooks
.Filename = "Input??.xls"
.Execute
End With
ReDim FName(1 To fs.FoundFiles.Count)
For i = 1 To fs.FoundFiles.Count
FName(i) = fs.FoundFiles(i)
Debug.Print fs.FoundFiles(i)
Next i

Regards,
Per
 
B

Bob Zimski

Hi

Don't know why it worked for me now and not before. Must have been a brain
freeze.

Thanks much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top