+ Reply to Thread
Results 1 to 8 of 8

Rename multiple files in a folder with a macro - Existing Macro update

  1. #1
    Registered User
    Join Date
    08-29-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    83

    Rename multiple files in a folder with a macro - Existing Macro update

    Hi,

    My original thread is here:
    http://www.excelforum.com/excel-prog...h-a-macro.html

    I used Bernie Deitrick macro solution. See attached file.

    I have multiple files in a folder and I want to rename them automatically via a macro. I use Excel 2016. Could you please update the macro for the following output:

    BEFORE

    The existing file names are:

    Firstname Surname_SOMETEST.html
    OR
    Firstname Middlename Surname_SOMETEST.html

    AFTER

    I would like the macro to rename the files to:

    Firstname Surname _ Test.html
    OR
    Firstname Middlename Surname_Test.html

    Basically the macro should replace any text after the _ with the word "Test". If there are duplicate files with the same name, the macro should ignore those records.

    Could you please help me with the requirement?

    Thank you,
    Ash
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Rename multiple files in a folder with a macro - Existing Macro update

    To borrow Bernie's code, this should work.
    Might be a good idea to try it with copied files in a temp folder first.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-29-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Rename multiple files in a folder with a macro - Existing Macro update

    Hi,

    I tried only the code you sent above and it did not work. When I run the macro nothing happens. Please check:

    Sub RenameFiles()
    Dim objShell As Object
    Dim objFolder As Object
    Dim objFile As Object

    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(ThisWorkbook.Path)

    For Each objFile In objFolder.Items
    If objFile.Name Like "*.html" Then
    objFile.Name = Split(objFile.Name, "_")(0) & "_Test.html"

    End If
    Next objFile

    End Sub

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Rename multiple files in a folder with a macro - Existing Macro update

    Re: "Please check"
    Unfortunately there is very little to check at this end because it works as advertised.
    Is your excel file with the code in the same folder as all the files that need their name changed?

  5. #5
    Registered User
    Join Date
    08-29-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Rename multiple files in a folder with a macro - Existing Macro update

    Yes, the file is on the same folder.

    Do I need to just use the above code? Or does it need to be used with in conjunction with existing Bernie's Macro?

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Rename multiple files in a folder with a macro - Existing Macro update

    All files, the .htm and the excel file with the code in it, need to be in the same folder.
    Open the excel file with the code in it from Post #2 and run it.
    Note that it is .htm in the code. If your extension is different, change the two lines to whatever your extensions are.
    To answer your question, the code from Post #2 should do what you've requested.

  7. #7
    Registered User
    Join Date
    08-29-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Rename multiple files in a folder with a macro - Existing Macro update

    Hi, still does not work. I have attached the macro file. I am unable to attach a html file here. You may download any html file from the web to check. Please advise?
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Rename multiple files in a folder with a macro - Existing Macro update

    I don't know what the problem could be. It works like a dandy here.
    The only thing I did was save files from outlook in .htm format in the folder. I did not, and will not, download and save from the web.

    See if this is any better. There in no error checking in the code so you need to add that.
    Only the excel file and the files to be renamed in Folder.
    Please Login or Register  to view this content.

+ 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 Multiple PDF files in a folder per the list in Excel spreadsheet
    By vmanil75 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2017, 09:40 AM
  2. [SOLVED] Rename multiple files in a folder with a macro
    By nobleprince in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-24-2016, 09:55 PM
  3. RENAME - Multiple files - Macro or not Macro?
    By heatwave in forum Excel General
    Replies: 1
    Last Post: 04-13-2015, 06:08 AM
  4. Macro to move files from one folder to another but rename duplicates
    By mark_anthony in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-09-2014, 06:56 AM
  5. Macro to open consecutively .TIFF files in 1 folder and rename them?
    By tedikoleva in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-09-2014, 03:28 PM
  6. Replies: 1
    Last Post: 03-12-2013, 04:45 AM
  7. [SOLVED] Rename multiple files in folder
    By MissaLissa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-17-2013, 04:14 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