+ Reply to Thread
Results 1 to 10 of 10

How to tell user If unable to locate an excel file without showing runtime error

  1. #1
    Registered User
    Join Date
    04-08-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    6

    How to tell user If unable to locate an excel file without showing runtime error

    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?

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to tell user If unable to locate an excel file without showing runtime error

    In a nutshell thats what you need.


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-08-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: How to tell user If unable to locate an excel file without showing runtime error

    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?

  4. #4
    Registered User
    Join Date
    04-08-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: How to tell user If unable to locate an excel file without showing runtime error

    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?

  5. #5
    Registered User
    Join Date
    04-08-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: How to tell user If unable to locate an excel file without showing runtime error

    When I step the code, runtime error happening on the first line of nutshell

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to tell user If unable to locate an excel file without showing runtime error

    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?

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to tell user If unable to locate an excel file without showing runtime error

    I have just tried this and it works.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to tell user If unable to locate an excel file without showing runtime error

    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.

  9. #9
    Registered User
    Join Date
    04-08-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: How to tell user If unable to locate an excel file without showing runtime error

    Hi Mehmetcik,

    This code works perfectly fine for me. It solved the issue. Thanks a lot for the helping hand

  10. #10
    Registered User
    Join Date
    04-08-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: How to tell user If unable to locate an excel file without showing runtime error

    Hi Mehmetcik,

    This code works perfectly fine for me. It solved the issue. Thanks a lot for the helping hand

    Quote Originally Posted by mehmetcik View Post
    I have just tried this and it works.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1