3

I'm trying to develop a bit of VBA that will check the date modified section on the file. I have found a bit of code online that uses the FileSystemObject to do this, but I run into a "Type Mismatch" error in VBA and was hoping someone could help..

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

(naturally i have entered the actual filepath there!)

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 have just added the Microsoft Scripting Runtime Reference, but this is still not working. Any ideas? Am I missing other required references?

Thanks in advance Alex

1 Answer 1

1

The problem is that you declare a variable FileLastModified in your test procedure, that has the same name as the function you want to call. If you delete that line it should work:

Sub test()
    MsgBox FileLastModified("S:\FILEPATHISHERE.xls")
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.