+ Reply to Thread
Results 1 to 13 of 13

Macro to rename workbook

  1. #1
    Registered User
    Join Date
    12-17-2008
    Location
    Singapore
    MS-Off Ver
    2002
    Posts
    71

    Macro to rename workbook

    Hi all, Everyday I receive 20 workbooks, named as date_xxx_xxx.wk1, where xx represent some random number. Example : 09032009_23_345.wk1.
    These files are stored in a folder which contain all the files received for a month.

    I need to rename them on a daily basis. I have 3 cell in my worksheet.
    Cell A1: C:\Report ( location of the folder)
    Cell A2: 09032009 ( a search criteria for file name)
    Cell A3: mb ( location , which I can change )

    When I run the macro. It will pick up Cell A1 as the folder to work on. Followed by It will search through the folder for files name containing Cell A2. Then It is found, It will pick up the cell value B1 in the current worksheet.
    lastly it will rename the files as "Cell A2_CellA3_CellB1.xls" . For example if the cell B1 in the workbook is Car. The file name will be "09032009_mb_Car.xls".

    Or anyone know the code to rename the workbook, with the cell valueB1 for example ?
    Last edited by kaffal; 03-10-2009 at 11:46 AM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro to rename workbook

    This saves the active workbook as the values in the three cells you specified. Put it in a module.

    Please Login or Register  to view this content.
    It should work, but I'm uncertain because you say the extension currently used is .wk1.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    12-17-2008
    Location
    Singapore
    MS-Off Ver
    2002
    Posts
    71

    Re: Macro to rename workbook

    hi , yr macro works but I still dunno how to apply to my code. I attached a sample of my code.
    i want to rename the file as "fcriteria_Tabname.xls" where fcriteria and Tabname are string in the code.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro to rename workbook

    I think you should add .value after your range() when you define your variables, then go:

    Please Login or Register  to view this content.
    and put that in whatever step you want to save it.

  5. #5
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro to rename workbook

    Maybe like this?:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-17-2008
    Location
    Singapore
    MS-Off Ver
    2002
    Posts
    71

    Re: Macro to rename workbook

    I added the line after. But it does not rename the workbook

    Please Login or Register  to view this content.

  7. #7
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro to rename workbook

    I don't see the line you are talking about. Where did you put it?

  8. #8
    Registered User
    Join Date
    10-15-2011
    Location
    bangalore
    MS-Off Ver
    Excel 2010
    Posts
    99

    Re: Macro to rename workbook

    hi ,

    when i run this macro it says object deos not support .for with application.filesearch , i think is that any reference to be included , please advice

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro to rename workbook

    Support for the FileSearch method was discontinued in Excel 2007.
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Registered User
    Join Date
    10-15-2011
    Location
    bangalore
    MS-Off Ver
    Excel 2010
    Posts
    99

    Re: Macro to rename workbook

    will it run in 2003 or 2010

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro to rename workbook

    Yes and no respectively.

  12. #12
    Registered User
    Join Date
    10-15-2011
    Location
    bangalore
    MS-Off Ver
    Excel 2010
    Posts
    99

    Re: Macro to rename workbook

    could not get your answer i am sorry , 2010 is yes and 2003 is no , is it?

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro to rename workbook

    It was discontinued in 2007, so earlier versions work and later versions don't.

+ 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