+ Reply to Thread
Results 1 to 8 of 8

macro to rename sheet as per workbook names

  1. #1
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    macro to rename sheet as per workbook names

    I have a folder with lot of workbooks in which there is only one sheet per workbook.

    Am looking a macro that renames all worksheets (excel) similar to their workbooknames within a folder (loop).

    The files are found c:\TESTA\

    ANNEXED a copy of the directory

    found a similar thread but did not work

    https://stackoverflow.com/questions/...es-in-a-folder

    Can someone assist
    Attached Images Attached Images

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: macro to rename sheet as per workbook names

    When you say that the example that you got from the similar thread did not work....

    Which one of the examples were you trying?

    What error message (if any) did you get.

    It would help if you posted the actual code that you tried to run and the error description.
    Martin

  3. #3
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: macro to rename sheet as per workbook names

    I got compile error variable not defined at i = 1



    Please Login or Register  to view this content.
    Attached Images Attached Images

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: macro to rename sheet as per workbook names

    OK - Try

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: macro to rename sheet as per workbook names

    Have a try indeed nothing happens.

    I have changed path to testa1 as a test for 2 files .

    Nothing happens

    However ,I have a new code, it works but issue each time give message

    Please Login or Register  to view this content.
    Be careful of your documents may include personal information that can;t be removed by document inspector.

    Since I have 300 files . It is boring to click ok each time.

    Any way to get rid of that message.
    Attached Images Attached Images
    Last edited by JEAN1972; 01-06-2019 at 04:14 PM. Reason: new code

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: macro to rename sheet as per workbook names

    How about this.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 01-08-2019 at 03:31 AM. Reason: Fixed error in code
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  7. #7
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: macro to rename sheet as per workbook names

    tried but unsucessful getting compile error message

    for each control variable must be variant or object.
    Attached Images Attached Images

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,231

    Re: macro to rename sheet as per workbook names

    Please Login or Register  to view this content.

    My apologies...only now had a look at bakerman2's code which works with this variable declaration...
    Please Login or Register  to view this content.
    Last edited by sintek; 01-07-2019 at 02:44 PM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Rename Excel column names in a closed workbook using ADOX
    By junoon in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-29-2016, 03:56 PM
  2. [SOLVED] Copy a sheet, rename it by value in range then export product to new workbook and rename
    By MagicMan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2015, 07:24 PM
  3. Macro to copy the active sheet to new workbook and rename
    By shansakhi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-06-2014, 01:27 AM
  4. Macro to Rename One of Two Identical Column Names
    By paulkem in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-08-2013, 03:48 PM
  5. Replies: 2
    Last Post: 09-04-2012, 01:19 AM
  6. Replies: 0
    Last Post: 04-28-2012, 06:06 PM
  7. rename/trim sheet names
    By longhorn23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-27-2010, 12:32 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