+ Reply to Thread
Results 1 to 4 of 4

Simplest way to remove invalid filename characters

  1. #1
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Simplest way to remove invalid filename characters

    Hello - I have 2 burning questions about these routines

    This SAVE_FILE subroutine here is supposed to save a workbook to a specific directory with a very specific name -- based on the worksheet's data.

    To create the name I'm cleaning the entry using another function... i want to remove anything that is not a Letter (A,a,B,b...Z,z) number (0,1,2,...,9) or allowed other characters ("#", "_", "-").

    Question: Is there a simple statement within excel VBA to handle this -- seems like there should be a statement like:
    IF mid(string,index,1) IS Alphanumeric OR IN("_",...) THEN

    As you can see below i'm checking each member of the name string against an array i created in another private function....just seems like a long way around the barn so to speak.

    (most of the sub is omitted...the rest is in the attachment for all to view)
    Please Login or Register  to view this content.
    This is the check-function
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by GeneralDisarray; 10-05-2011 at 03:37 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Simplest way to remove invalid filename characters

    Maybe this would help?

    http://www.codeforexcelandoutlook.co...ate-filenames/

    or

    http://www.ozgrid.com/forum/showthre...t=42503&page=1

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Simplest way to remove invalid filename characters

    I'd suggest a for next loop, thus:
    Please Login or Register  to view this content.
    Note: untested...
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Simplest way to remove invalid filename characters

    looks like what i need, thank you

+ 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