+ Reply to Thread
Results 1 to 7 of 7

Check if file exists (allows users to input file path in cell)

  1. #1
    Registered User
    Join Date
    05-29-2014
    MS-Off Ver
    2016
    Posts
    31

    Check if file exists (allows users to input file path in cell)

    Please Login or Register  to view this content.
    The above code can find out if a file exists and output the result in row C when I hard code the path into
    LPath = "C:\Users\Admin\Desktop"
    However, I want to let the user input the path in, say cell D1 so that there is no need for the user to modify the VBA code
    I tried replacing with LPath = Range("D1").Value
    But it does not work
    What should I do to allow the user to input the path in cell D1 ?

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Check if file exists (allows users to input file path in cell)

    Since you're automating Word, why not simply have the user use Word's FileOpen dialog to select the document? That way, you don't need to test for the file's existence.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    05-29-2014
    MS-Off Ver
    2016
    Posts
    31

    Re: Check if file exists (allows users to input file path in cell)

    Quote Originally Posted by macropod View Post
    Since you're automating Word, why not simply have the user use Word's FileOpen dialog to select the document? That way, you don't need to test for the file's existence.
    Because the user has the list of file names (stored in row B) in an Excel file and the user wants to check if any of the file is missing in a particular folder (the folder contains all the word files (but a few are missing) with the file names in that row).

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Check if file exists (allows users to input file path in cell)

    So what is it about inserting the filepath in cell D1 that didn't work?

  5. #5
    Registered User
    Join Date
    05-29-2014
    MS-Off Ver
    2016
    Posts
    31

    Re: Check if file exists (allows users to input file path in cell)

    Quote Originally Posted by macropod View Post
    So what is it about inserting the filepath in cell D1 that didn't work?
    The VBA failed to find any file when using LPath = Range("D1").Value. The output is No for every file.
    But the VBA could output the file that exists as Yes when I used LPath = "C:\Users\Admin\Desktop".

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Check if file exists (allows users to input file path in cell)

    Since the path is missing the terminating '\' in the macro, if that's what you input into D1, it's not likely to work in either, since your code doesn't supply it anywhere else.

  7. #7
    Registered User
    Join Date
    05-29-2014
    MS-Off Ver
    2016
    Posts
    31

    Re: Check if file exists (allows users to input file path in cell)

    Quote Originally Posted by macropod View Post
    Since the path is missing the terminating '\' in the macro, if that's what you input into D1, it's not likely to work in either, since your code doesn't supply it anywhere else.
    Thanks. It works now.

+ 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. HOW CHECK FILE.NAME HAS EXISTS OR NOT IN FOLDER,if not exists then copy
    By daboho in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-13-2018, 03:50 AM
  2. Check if file exists based on value in specified cell
    By Andy Swain in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-06-2018, 09:16 AM
  3. How to check if file exists if path is not known
    By yondaime in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2014, 04:43 AM
  4. [SOLVED] Check if file exists and if so save file incremented by 1 e.g. filename(1).xlsm
    By ratdogexcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2014, 01:15 AM
  5. check if file exists and opening it based on file date
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-26-2014, 03:45 AM
  6. [SOLVED] Get file path from a cell, run a check to see if the file has a specific sheet if yes copy
    By Martha44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-04-2013, 03:35 AM
  7. Macro to check file exists and take input from the file
    By naidu9295 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-12-2010, 08:15 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