Results 1 to 2 of 2

How Can The Macro Rename Files When The Original File Name Changes Everday

Threaded View

  1. #1
    Registered User
    Join Date
    08-17-2008
    Location
    London
    Posts
    18

    How Can The Macro Rename Files When The Original File Name Changes Everday

    Hi I'm quite new to Excel VBA so I'm having a bit of trouble with the codes that Excel uses but I know the overall steps of my program and the logic behind it. I would be greatful if someone could guide me on this.

    - Suppose I have a folder with a list of 3 files, updated daily.

    - The 3 files are updated daily and named according to the current date. So for example, if it was Tuesday 28 July, the three files would be named:
    HOJ_20080728.xls
    UUL_20080728.xls
    QWK_20080728.xls

    If the date was September 29 2008 the files would be named:
    HOJ_20080929.xls
    UUL_20080929.xls
    QWK_20080929.xls

    and so on..


    - Now, I need my program to convert the files to a different name:
    For the "HOJ_date" file, the name needs to change to H11A.csv
    For the "UUL_date" file, the name needs to change to U22A.csv
    For the "QWK_date" file, the name needs to change 2 Q33A.csv

    This may seem easy but the problem is that the name of the original files change everyday because of the date.

    So I need the program to be able to change the file names to the ones I specified above everday, regardless of the fact that the date changes.

    I kind of have a "half-solution" but I'm not too familiar with the VBA terminology for codes so I will just list the overall kind of logic.
    -------------------------------------------------------------------------
    Suppose today is 15 March 2008, then:

    -------------------------------------------------------------------------
    \\ specify the day string
    Dim Day As String;
    
    \\ specify the day
    Day = "20080315"
    
    \\ now check the directory for all the files. Open them one by one and 
    change their file names and save as a new CSV file.
    
    Open file "C:\HOJ_" & Day & ".xls"
            SaveAs Filename:="H11A.csv", FileFormat:=xlCSVMSDOS
    Close file
    
    Open file "C:\UUL_" & Day & ".xls"
            SaveAs Filename:="U22A.csv", FileFormat:=xlCSVMSDOS
    Close file
    
    Open file "C:\QWK_" & Day & ".xls"
            SaveAs Filename:="Q33A.csv", FileFormat:=xlCSVMSDOS
    Close file
    -------------------------------------------------------------------------

    So that's the overall logic I wanted to implement.
    The program gets all the files from the folder and opens them one by one and saves a CSV version with new names.

    Do you think this may be possible?

    Please do help me.

    - The only hard thing I reckon is the fact that I don't know whether you can just open any file from the folder, in any order you want and then change the filename. And then open any other file you wish. Do you see what I mean?

    I would greatly appreciate your help.

    Many thanks.

    P.S this is getting quite long for me so if someone could get a solution then I would be over the moon and really greatful to you!
    Last edited by np123345; 09-01-2008 at 05:44 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 14
    Last Post: 04-17-2008, 04:12 PM
  2. Macro - Collect data - Select folder and loop through all xls files
    By kostas in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-04-2008, 05:58 AM
  3. vba to change macro file name
    By blackstar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-02-2007, 12:14 AM
  4. Summarize results from files into main file
    By aktarina in forum Excel General
    Replies: 4
    Last Post: 09-06-2007, 01:09 AM
  5. Macro to change file types
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2007, 05:50 PM

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