+ Reply to Thread
Results 1 to 5 of 5

rename "txt files from Excel macro

  1. #1
    Registered User
    Join Date
    05-26-2013
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    2

    rename "txt files from Excel macro

    Hi from Bulgaria,
    Please HELP
    I'm new in VBA and I need macro that will rename txt files.
    What I have is text files stored in a folder, let's say:
    D\AIR\:
    Each file is named as follows

    AIR_2054.TXT
    AIR_2055.TXT
    AIR_2056.TXT ect...

    What I need is macro that will read specific line form D\AIR\:"AIR_*.TXT" files and rename it ,depends on it contents

    The Text files are different type , let's say 5 type


    TYPE 1 check only in line 2 - /most common /
    if mid(line2,13,5)="AGENT" then rename file as BIR_2054.TXT /change first string of file name from A to B/
    [B]
    [B]TYPE 2 check only in line 3
    if mid(line3,2,3)="EMD" then rename file as EIR_2055.TXT /change first string of file name from A to E/

    TYPE 3 check only in line 2
    if mid(line2,18,3)="MCO"then rename file as MIR_2055.TXT /change first string of file name from A to M/

    TYPE 4 check only in line 1
    if mid(line1,1,16)="AUTOMATED REFUND"then rename file as RIR_2055.TXT /change first string of file name from A to R/

    TYPE 5 -
    NOTHING MATCH TO TYPE 1,2,3,4 THEN rename file as xIR_2055.TXT /change first string of file name from A to x/

    Notes
    *If one of the file contain data of ONE TYPE it is not possible to contain other TYPES*
    *Some of the types start from 2-nd line /first line is blank/


    I hope that you understand me:-)
    Thanks in advance
    Teodora

  2. #2
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Kolkata, India
    MS-Off Ver
    Excel 2003/2007
    Posts
    182

    Re: rename "txt files from Excel macro

    Hi Teodora,

    Welcome in Excel Forum.

    Please let me clear few confusion.
    As you have mentioned in notes that "Some of the types start from 2nd line /first line is blank"--
    then what happen for Type 2 (say)- should we start finding "EMD" in line 4? (same confusion for remaining types).

    regards
    taps

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: rename "txt files from Excel macro

    Untested, this seems to be sound for what you're trying to do. This will create a DONE folder inside your AIR folder and renamed files will go in there. This is to avoid an infinite loop of TXT files by the name changing.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    05-26-2013
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: rename "txt files from Excel macro

    Thank you very match!!!!
    I mede some changes that match my needs and code works perfect
    Regards Teddy

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: rename "txt files from Excel macro

    As I expected you would. Glad to hear it's working for you.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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