+ Reply to Thread
Results 1 to 4 of 4

Function to check if string is valid/legal windows file name?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Exclamation Function to check if string is valid/legal windows file name?

    I am looking for code to check if a proposed save path (as string) is OK. However both the functions I have found so far - DO. NOT. WORK!

    I found this code on the net http://www.jpsoftwaretech.com/excel-...ate-filenames/
    Please Login or Register  to view this content.
    But it always returns False whenever I test it. The web page states: "I've modified the original code ever so slightly; the asterisks just inside the quotation marks in Ross' code are unnecessary, if the Visual Basic Help System is to be believed." I tried adding asterisks between the symbols but that only gives me a syntax error.

    So I searched again and found this:
    Please Login or Register  to view this content.
    But this is no good because it doesn't check for all the invalid symbols (full list located here: http://msdn.microsoft.com/en-us/library/aa365247.aspx)

    So I tried modifying the above code (see my attempt below) but I end up with Syntax error again!
    Please Login or Register  to view this content.

    Can anyone please provide a working function for what I am seeking and/or please let me know what is wrong with the above two functions?
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Function to check if string is valid/legal windows file name?

    The thing that's throwing your syntax out is the quotation mark.. Try this instead

    lstIllegal = Array("<", ">", ":", Chr(34), "/", "\", "|", "?", "*")
    Elegant Simplicity............. Not Always

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Function to check if string is valid/legal windows file name?

    Quote Originally Posted by AndyLitch View Post
    The thing that's throwing your syntax out is the quotation mark.. Try this instead

    lstIllegal = Array("<", ">", ":", Chr(34), "/", "\", "|", "?", "*")
    So THAT'S what was causing the problem! Thanks! +1

    If it's not asking too much, do you know what is causing the first function to screw up? (If I had a choice between working versions of both, I would prefer the first function )
    Last edited by mc84excel; 04-29-2013 at 12:35 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Function to check if string is valid/legal windows file name?

    The first function has been solved by Jindon. (http://www.excelforum.com/excel-prog...elimiters.html)

    Thank you everyone.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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