Reputation: 43
I want to open workbook up to variable in the archive list.
If I don't have the file in the archive, I want it to show a message box, but it did not work.
strVariable = Left(PictureNo, 4)
d = "Teknik Resim Arsiv Listesi_" & strVariable & ".xls"
Dim Ret
Ret = Workbooks.Open(ThisWorkbook.Path & Application.PathSeparator & d)
If Ret = False Then
MsgBox "Not Found"
End If
Upvotes: 0
Views: 49
Reputation: 23994
Check for the existence of the file before attempting to open it:
strVariable = Left(PictureNo, 4)
d = "Teknik Resim Arsiv Listesi_" & strVariable & ".xls"
If Dir(ThisWorkbook.Path & Application.PathSeparator & d) = "" Then
MsgBox "Not Found"
Else
Dim wb As Workbook
Set wb = Workbooks.Open(ThisWorkbook.Path & Application.PathSeparator & d)
End If
Upvotes: 1