I have a program that opens many excel files. But if the program cannot find the designated file, how to pop up a message telling that file not found instead of runtime errors? Anyone can help?
I have a program that opens many excel files. But if the program cannot find the designated file, how to pop up a message telling that file not found instead of runtime errors? Anyone can help?
In a nutshell thats what you need.
If (Dir(FileName) = "") Then FileThere = False Else: FileThere = True End If
Sample of my program is like this
Workbooks.Open Filename:=_
"C:\xxxx\xxxx"
ActiveWindow.Close
May I know how to use the nutshell you mentioned inside?
I gave like this
If (Dir(FileName) = "C:\xxx\xxx") Then
FileThere = False
MsgBox "no file found"
Else
FileThere =True
ActiveWindow.Close
Endif
But it having runtime error Type mismatch. What should I do?
When I step the code, runtime error happening on the first line of nutshell
I have just tried this and it works.
Sub Macro2() ' ' Macro2 Macro ' ' ChDir "C:\Documents and Settings\Owner\Desktop" If (Dir("Book1.xlsm") = "") Then Beep MsgBox "Sorry File Not Found!!!!", vbExclamation, "File Exists?" Else: MsgBox "Success File Found!!!!", vbOKOnly, "File Exists?" End If End Sub
Hi Mehmetcik,
This code works perfectly fine for me. It solved the issue. Thanks a lot for the helping hand
Hi
Sorry I wasn't aware that you were on line.
Can you tell me which directory you want to look in and the file name?
The first line tells excel which director to look in. The best way to get that is to record a macro and save to that directory.
The second line is looking for file Book1.xlsm in that directory. The best way to get the filename is to record a macro and open the file.
The rest should be self explanatory.
I hope That Helps.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks