Link to home
Create AccountLog in
Avatar of alam747
alam747

asked on

would you please tell me whats the problem the VBA code below and how to resolve it.

I got compile error telling 'Type mismatch' its not clear to me whats the problem and how to fix it

Sub ListFiles()
Dim aryFiles() As String
Dim strMessage As String
Dim strFile As String

aryFiles = directory.getfiles("C:\ConvertToExecl", "*.pdf")
strMessage = "Found" & aryFiles & "pdf files." & vbCrLf & vbCrLf
For Each strFile In aryFiles
    strMessage = strMessage & strFile & vbCrLf
Next
MsgBox (strMessage)

End Sub
Avatar of Dale Harris
Dale Harris
Flag of United States of America image

Where is Directory created?
Avatar of alam747
alam747

ASKER

Directory is in C: drive named ConvertToExcel where all pdf files exist.
Okay, I couldn't figure out the exact way to do it, but to get you a little closer (as I'm leaving for the day soon), you can't put

strMessage = "Found" & aryFiles & "pdf files." & vbCrLf & vbCrLf

down because aryFiles is not a count of files.  You will need to do some kind of UBound command or something.

Also, are you sure you can assign "Directory.GetFiles" to a string array, or do you need a file object array?

Unless it's only getting the names of it.

Lastly, for each strFile in aryFiles, strFile has to be a variant is what the debugger told me.

Sorry about not providing the answer.  I have to sleep eventually ;)

HTH,

Dale Harris
Avatar of alam747

ASKER

Thanks for your comments,
ASKER CERTIFIED SOLUTION
Avatar of Nick67
Nick67
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of alam747

ASKER

thanks