Find file that could be in one of three locations
i need to write a vba script that will find开发者_如何学Python a file. the file could be in three different locations
how do i find where the file is?
the file must have a specific string as part of the file name
my file name could be 9424.bas or 9424a.esy or 9424_.bas or 9424...esy, i dotn know what the file name exactly is but i know the important characters 9424
If Dir("file_location_1") <> "" Then
''# File is in 1
ElseIf Dir("file_location_2") <> "" Then
''# File is in 2
ElseIf Dir("file_location_3") <> "" Then
''# File is in 3
Else
''# File is not found
End If
For more than three possible locations an Array and a For loop would be the nicer solution.
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("folder1" + "filename") then
' folder1
ElseIf fso.FileExists("folder2" + "filename") then
' folder2
ElseIf fso.FileExists("folder3" + "filename") then
' folder3
End If
精彩评论