Thread: [Solved] Excel/VBS DIM MyFSO error
View Single Post
 
Old 04-26-2021, 03:35 AM
p45cal's Avatar
p45cal p45cal is offline Windows 10 Office 2019
Expert
 
Join Date: Apr 2014
Posts: 867
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

If this is only for that little macro it's probably not worth adding the reference to the project, use late binding instead:
Code:
Sub CheckFileExist()
Dim MyFSO As Object
Set MyFSO = CreateObject("Scripting.FileSystemObject")
If MyFSO.FileExists("C:\temp\text.txt") Then
  MsgBox "The File Exists"
Else
  MsgBox "The File Does Not Exist"
End If
End Sub
but perhaps easier:
Code:
Sub CheckFileExist2()
If Dir("C:\temp\text.txt") = "" Then
  MsgBox "The File Does Not Exist"
Else
  MsgBox "The File Does Exist"
End If
End Sub
Reply With Quote