Results 1 to 3 of 3

Thread: Valid Filename

  1. #1
    Join Date
    Dec 2004

    Unanswered: Valid Filename

    I am putting together an tool that will allow users to save certain sheets in a book to another file and I want to let the user decide the name of the file.

    I have the path part of this worked out, but need help on the filename.

    Is there a quick method of finding out whether a filename will be OK.

    For example I wnt to ensure that they have not used a full stop (Because I will add the ".xls" and backslases are also a pain because they becaome part of the path.

    Is there a ValidFilename function somewhere or will I have to write one and loop thruough all the characters ensuring that none of the above are used.


  2. #2
    Join Date
    Jun 2006
    Colton, CA
    You could use Right() and check the last 4 chars of the string rather than using mid() to check every char...
    Geek it till it mHz

  3. #3
    Join Date
    Feb 2004

    if your not using the built-in GetSaveAsFilename dialog to get the user input you should consider using that. It allows you to define the file type list and you can change the current directory prior to displaying it. See the MS Excel VB Help on this for the GetSaveAsFilename Method.

    To get only a path from a full path and file name string, Use a loop with the 'Mid' function to check each charter in the full path working backwords until you get a "\" backslash. Then use 'Left' with the loop count to get only the path less the file name.

    You can use the 'Dir()' function to check for a valid path or path and file. using the getsaveasfilename dialog will eliminate many problems of bad user input.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts