Excel VBA File System Object

I am trying to develop a VBA bit that will check the modified date section in a file. I found a bit of code on the internet that uses FileSystemObject to do this, but I ran into a "Mismatch Type" error in VBA and hoped someone could help.

Sub test()
Dim FileLastModified As Variant
MsgBox FileLastModified("S:\FILEPATHISHERE.xls")
End Sub

      

(of course I entered the actual file path!)

Function FileLastModified(strFullFileName As String)
Dim fs As Object, f As Object, s As String

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(strFullFileName)

s = UCase(strFullFileName) & vbCrLf
s = s & "Last Modified: " & f.DateLastModified
FileLastModified = s

Set fs = Nothing: Set f = Nothing
End Function

      

I just added a Microsoft Scripting Runtime link, but that still doesn't work. Any ideas? Am I missing other required links?

Thanks in advance Alex

+3


source to share


1 answer


The problem is that you are declaring a variable FileLastModified

in your test procedure that has the same name as the function you want to call. If you remove this line, it should work:



Sub test()
    MsgBox FileLastModified("S:\FILEPATHISHERE.xls")
End Sub

      

+1


source







All Articles