+ Reply to Thread
Results 1 to 9 of 9

Find Filename with VBA

  1. #1
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    100

    Find Filename with VBA

    Is it possible to create a vba code that is able to check whether or not a file exists.
    Basically, I would have a userform with a textbox where a user is able to type in a filepath with filename.
    Upon clicking a button the code would check if if that file exists or not. If not then it would pop a msgbox.
    No idea if that's possible. Any suggestion?

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Find Filename with VBA

    Try the function below. strDirectoryPath is path of the file.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Find Filename with VBA

    A google search of vba code to check if file excist will give plenty of codes. Heres just one link

    http://www.excelguru.ca/content.php?157
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  4. #4
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    100

    Re: Find Filename with VBA

    @JieJenn

    Do I create a new module for the function you provided and can I then include that function in my userform button?
    I am asking, because I have a userform where a user can enter the directory path and filename, and based on these textboxes I would like to check whether or not the file exists to continue working on the new workbook.

    Thanks in Advance

  5. #5
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Find Filename with VBA

    You copy and paste into a standard module and you treat it like a function that you normally use on daily basis.

  6. #6
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    100

    Re: Find Filename with VBA

    Alright, what if I want the function to work in a User Form like the one I attached below?

    Pretty much I am debugging my userform rightnow and my goal is to show a msgbox when the the filename does not exists. Hopefully my attachment makes more sense...
    Attached Files Attached Files

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Find Filename with VBA

    Maybe something like this. Im not sure exactly what your trying to do though.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Find Filename with VBA

    the code will look like if file does not exist

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    100

    Re: Find Filename with VBA

    Thanks guys your are geniuses...!!

+ 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