+ Reply to Thread
Results 1 to 12 of 12

Check if file exists

  1. #1
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Check if file exists

    Hi All,

    I have a sheet that has variable list of file name and location. So as its variable I don't know the length of the list as it changes.
    The file location will be in column C and look like:

    C:\Documents and Settings\jtb\Desktop\JB7test\jb1.xls

    I would like to run down column C and check that each file exists and if not message that file XXX does not exist.

    I am sure it stars like below but I am stuck here, can anyone help?


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Check if file exists

    This macro display on column 'D' if file of columnd 'C' exists or does not exist:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Check if file exists

    You could possibly modify this to suit your needs, and then put it in a suitable loop.

    Please Login or Register  to view this content.

    Hope this helps

  4. #4
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Re: Check if file exists

    Hi Guys,

    I am trying to mix the both but get an run time error 54 on line

    Please Login or Register  to view this content.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Check if file exists

    Post the all of the code you have "mixed", so we can understand your problem better.

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Check if file exists

    I can't really see why you would get a bad file mode error when you are not trying to write anything to the file, so yes, the whole code would be useful!
    Remember what the dormouse said
    Feed your head

  7. #7
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Re: Check if file exists

    I gave up the but the code is
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Re: Check if file exists

    Oh its run time error 52.

    Please Login or Register  to view this content.

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Check if file exists

    For error 52 (bad file name or number) I'd say you have invalid characters in one of your cells. (For example, a file name cannot include a colon).

  10. #10
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Re: Check if file exists

    As in the colon next to the C?
    C:\Documents and Settings\jtb\Desktop\JB7test\jb1.xls
    Then how can you put a location in?

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Check if file exists

    No, the colon is fine there, but cannot appear in a folder or file name. There are other illegal characters too. What is the value of the cell when your code fails?

  12. #12
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Check if file exists

    To add to rompers' last post

    From Help
    Excel workbook file names cannot include characters with mathematical formula or wildcard characters. For example, inclusion of a square bracket will corrupt the worksheet names used in the workbook. It is possible for Internet Explorer to include invalid characters automatically in some cases when the file is downloaded from a Web site.
    To avoid this error, do not add invalid characters to the name of workbooks or worksheets in Excel.
    It is also recommended to not use double quotes, parenthesis, or other characters as part of a file name or worksheet name. These characters may be considered "string delimiters" or special operators for the language your system is configured to use. This is especially true if you are using any Visual Basic for Applications (VBA) programming or string handling methods with these files. Common string delimiters for US English are:
    " (straight quotation mark)
    ' (single straight quotation mark)
    ~ (tilde)
    [ ] (brackets)
    { } (braces)
    ( ) parentheses
    & (ampersand)
    # (number sign)
    * (asterisk)
    : (colon)
    ? (question mark)
    | (vertical bar)
    + (plus sign)
    > (greater than)
    < (less than)
    . (period)
    \ (backslash)
    Cheers

+ 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