I have the following piece of code, that is supposed to open one or another file depending on the value in a cell. The problem is that it returns an error saying that the file may have been moved or deleted. The file name is partial, but the error returns the full name of the workbook. Meaning that it finds it in the folder, as I can clearly see it. Any ideas why? Error line marked.
strPeriod = ThisWorkbook.Sheets("Admin").Range("D8").Value
strName = ThisWorkbook.Sheets("Admin").Range("D9").Value
strPath = ActiveWorkbook.path & "\" & strPeriod & "\" & strName & " " & strPeriod & " v1.xlsm"
strName2 = strName & " " & strPeriod & " v1.xlsm"
Dim directory As String, fileName2 As String, sheet As Worksheet, total As Integer, LatestFolder As String, PnL As String, Comparitor As String
directory = "path\"
LatestFolder = ThisWorkbook.Sheets("Admin").Range("D8").Value
PnL = "*Air*"
Comparitor = "Comparitor.xlsm"
If strName = "Air" Then
fileName2 = Dir(directory & PnL)
Else
fileName2 = Dir(directory & LatestFolder & "\" & Comparitor)
End If
Workbooks.Open fileName:=strPath
Workbooks.Open fileName:=fileName2, ReadOnly:=True
Bookmarks