+ Reply to Thread
Results 1 to 2 of 2

If File Not Found In Either Directory Then Message "File Not Found"

  1. #1
    Registered User
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    2007
    Posts
    65

    If File Not Found In Either Directory Then Message "File Not Found"

    Hello,

    I'm trying to write an If ElseIf Else statement where my macro looks up the extension of a file name (located in Sheet2 H1) and searches through a folder based on what that value is. If that file does not exist, it crashes my macro and takes me into debug mode. I'd rather have it come up with an error message, with another opportunity to get the file name correct. Since I'm still learning VBA, I'm going to give this example in a format that is easier to understand:

    If Filename ends in ".csv" Then
    Open C:\csv\ & sheet2.range("H1")

    ElseIf Worksheets("Sheet2").Range("H1") = ".xls" Then
    Open C:\xls\ & sheet2.range("H1")

    ElseIf Worksheets("Sheet2").Range("H1") = ".txt" Then
    Open C:\txt\ & sheet2.range("H1")

    Else Message "Cannot Find File"

    End If

    Thanks in advance.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,121

    Re: If File Not Found In Either Directory Then Message "File Not Found"

    Maybe...
    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Workbooks.Open method and runtime error 1004 - "file couldn't be found".
    By PHBlaz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-28-2014, 02:10 PM
  2. Replies: 1
    Last Post: 11-23-2013, 05:50 AM
  3. [SOLVED] Message (in one window) for each file found/not found
    By kboy1289 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-08-2013, 04:03 PM
  4. Corrupt Reference file? "Method or Data Member Not Found"
    By manda_w in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2013, 07:51 PM
  5. [SOLVED] "File Not Found. Check the spelling of the file. . . "
    By cjaye in forum Excel General
    Replies: 3
    Last Post: 06-12-2012, 07:37 PM
  6. FileSystemObject.GetFile Error "File Not Found" in Excel 2007
    By treehugger87 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-12-2010, 01:44 PM
  7. [SOLVED] How do I install when "file ZF561407.CAB can not be found"
    By shelba in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 08-02-2006, 08:20 PM
  8. I Visual Basic Error "File Not Found" when Excel opens
    By Brent E in forum Excel General
    Replies: 1
    Last Post: 03-02-2005, 12:06 AM

Tags for this Thread

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