+ Reply to Thread
Results 1 to 12 of 12

Macro to change multiple file names (monthly)

  1. #1
    Registered User
    Join Date
    01-14-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Question Macro to change multiple file names (monthly)

    Hi all,

    I've been searching all day to find a simple macro that will rename a folder full of PDFs. It would be ideal if there was a macro that would pull the existing file names, drop them into excel, then I would drop in my desired new file names in a new column, and then I could press a button & have it run! I am BRAND NEW to using macros, I don't even know where to begin, so if someone could break this down as simple as possible, that would be fantastic.

    Folder location where the original files are, and where I'd like them to stay = S:\OFFICE\Fran\Pricers\!! SALE PRICERS\2014\2. Feb 2014 Sale\Feb 2014 - Spirits
    They are PDF files. Original files are named "FEB 2014 - ALL SPIRITS 1", and so on. I'd like to rename the files with the product name & size (ex: "Alize Liqueurs 750ml")
    Example of the Excel doc I have right now:

    COLUMN A COLUMN B
    FEB 2014 - ALL SPIRITS 1 Alize Liqueurs 750ml
    FEB 2014 - ALL SPIRITS 2 Amarula Cream Liqueur
    FEB 2014 - ALL SPIRITS 3 Antica Sambucas 750ml
    FEB 2014 - ALL SPIRITS 4 Bacardi 1873 Solera Rum 750ml
    FEB 2014 - ALL SPIRITS 5 Bacardi "8" Rum 750ml
    FEB 2014 - ALL SPIRITS 6 Bacardi Anejo 750ml
    FEB 2014 - ALL SPIRITS 7 Bacardi Strawberry Daquiri Light 750ml
    FEB 2014 - ALL SPIRITS 8 Bacardi Flavors 750ml
    FEB 2014 - ALL SPIRITS 9 Bacardi Gold Rum 750ml

    Etc....... goes on for 122 rows
    Last edited by awc7; 01-15-2014 at 09:05 AM. Reason: Change title.....

  2. #2
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: Simple macro for a dummy!

    Hi -

    Please try this one and let me know;

    Please Login or Register  to view this content.
    Event

  3. #3
    Registered User
    Join Date
    06-09-2011
    Location
    Newcastle, Australia
    MS-Off Ver
    2003, 2010
    Posts
    54

    Re: Simple macro for a dummy!

    Hi awc7

    Would I be right in assuming this exercise will be a monthly one ?
    Will it always be in the same workbook or a new workbook each month ?
    Would the PDF files be renamed ...
    eg, "FEB 2014 - ALL SPIRITS 1 Alize Liqueurs 750ml.pdf" ... as ... "Alize Liqueurs 750ml.pdf"
    If so, trimming the file names would not require any re-writing to the worksheet

    Changing code expressions in an Excel project on an ongoing basis (eg, each month) should be avoided because over time the file will become unstable.
    Excel is famous for it.

    There is no such thing as a simple macro.
    Such an exercise you are wanting will have to consider any variations you might want to make in the future, particularly the address of the target folder of PDFs each month ... or changes to the starting list.
    Last edited by GreyGhost; 01-14-2014 at 10:07 PM. Reason: updates

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Simple macro for a dummy!

    Hi, awc7,

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Registered User
    Join Date
    01-14-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Simple macro for a dummy!

    Quote Originally Posted by HaHoBe View Post
    Hi, awc7,

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Ciao,
    Holger
    I changed it. If that's not good enough please feel free to change it yourself.

  6. #6
    Registered User
    Join Date
    01-14-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Simple macro for a dummy!

    Quote Originally Posted by event21 View Post
    Hi -

    Please try this one and let me know;

    Please Login or Register  to view this content.
    Event
    I will try this & get back to you! Thank you!

  7. #7
    Registered User
    Join Date
    01-14-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Simple macro for a dummy!

    Quote Originally Posted by GreyGhost View Post
    Hi awc7

    Would I be right in assuming this exercise will be a monthly one ?
    Will it always be in the same workbook or a new workbook each month ?
    Would the PDF files be renamed ...
    eg, "FEB 2014 - ALL SPIRITS 1 Alize Liqueurs 750ml.pdf" ... as ... "Alize Liqueurs 750ml.pdf"
    If so, trimming the file names would not require any re-writing to the worksheet

    Changing code expressions in an Excel project on an ongoing basis (eg, each month) should be avoided because over time the file will become unstable.
    Excel is famous for it.

    There is no such thing as a simple macro.
    Such an exercise you are wanting will have to consider any variations you might want to make in the future, particularly the address of the target folder of PDFs each month ... or changes to the starting list.
    Hi GreyGhost!

    Yes, this is a monthly task (each month I have 3 sets of files I will need to rename). It will be a new work book each month.
    Sorry, the example I gave mashed both the old name & the new names together. The original would be "FEB 2014 - ALL SPIRITS 1.pdf" (then 2, 3, 4, so on), and the new name would be "Alize Liqueurs 750ml.pdf" (then Amarula Cream Liqueur 750ml, then Antica Sambucas 750ml, and so on).

    And I only said "simple" because I found this exact question all around the web (with solutions), but couldn't tailor any of them for my own problem. I know what you all do isn't easy

    Thanks so much for your help.

  8. #8
    Registered User
    Join Date
    01-14-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Simple macro for a dummy!

    Quote Originally Posted by event21 View Post
    Hi -

    Please try this one and let me know;

    Please Login or Register  to view this content.
    Event
    Hello! After changing the source folder path (see above, I edited to my paths.. should I take the quotes out?) I'm getting "Run-time error '52' Bad file name or number" and then it highlights the "fso.copyfile..." line when I go to debug.

  9. #9
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: Macro to change multiple file names (monthly)

    Hi -

    You can isolate the issue I believe.
    Create a simple local folder and then transfer few files in there and test the code.

    event

  10. #10
    Registered User
    Join Date
    01-14-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to change multiple file names (monthly)

    Quote Originally Posted by event21 View Post
    Hi -

    You can isolate the issue I believe.
    Create a simple local folder and then transfer few files in there and test the code.

    event
    YES!! It worked! I just think the source folder was too complicated, perhaps. A simple folder on the desktop worked just fine. Thank you, thank you!

  11. #11
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: Macro to change multiple file names (monthly)

    Hi -

    Glad it works.

    event

  12. #12
    Registered User
    Join Date
    06-09-2011
    Location
    Newcastle, Australia
    MS-Off Ver
    2003, 2010
    Posts
    54

    Re: Macro to change multiple file names (monthly)

    Hi AWC7

    When manipulating files with VBA ...
    If any file path (full-name) has a space in it, the full-name must be wrapped in extra double quotes.
    eg, "Program Files" folder is notorious for causing errors and you cannot use "Windows Environment Variables" %ProgramFiles% in the string (in VBA) either.

    Please Login or Register  to view this content.
    -----
    SIMPLE RENAMING (with VBA) no lists required
    Your PDF files can be renamed (if the new "file-name" is derived from a consistent default name), without referring to an Excel sheet list.
    Particularly if each batch of default PDFs are located in different folders each month.
    You can use an Excel XLSM project with a button on it to ...
    • Show a folder selector dialog, where you can browse to the holding folder.
    • Msgbox (yes/No) showing count of PDFs with common prefix on all files + option to continue or cancel
      eg, Found 120 PDF files with prefix ""FEB 2014 - ALL SPIRITS 1"" vbLf Do you want to continue?"
      You could create an extra worksheet (named "REFS") with one named cell where you can change the "prefix" if ever needed
    • after msgbox "Yes" ... all file renaming will be made to the existing PDF files
    • this would negate having to manually create an extra field/column of short-names in adjoining cells
      For memory I think you will have 120 (approx) files to rename, a lot of typing, and a risk of creating typos

    --OR--

    If you need to list the files in an Excel sheet, subject to...
    ... a new book each month -OR- a new sheet in an existing book each month

    NEW BOOK EACH MONTH
    Pros:- short names can be a totally new name, unrelated to the old-name string
    Cons:- a lot of typing to create shorter names + remember to alter code with folder-path to the PDF files
    • Create a template file, with macros/VBA in it
    • a sheet button (or ActiveX button) on the wsheet
    • Load your list of default-named PDFs (how ever that is done?)
    • sheet button to loop through list of default named PDFs and change the files names of each PDF file

    NEW SHEET EACH MONTH
    Pros:- short names can be a totally new name, unrelated to the old-name string
    Cons:- a lot of typing to create shorter names + a lot of manual steps, risk of errors by user.
    • create a new worksheet and name it "REFS"
    • Name two cells (project scope)
      1. NR_FOLDER_PATH ... (name is my suggestion, NR = named range)
      2. NR_TARGET_SHEET_NAME ...
    • Manually type new short names for all 120 files
    • in named cell "NR_FOLDER_PATH" copy past folder path
    • in named cell "NR_TARGET_SHEET_NAME" copy paste the target sheet-name
    • run macro to rename all PDF files

    For my money I would opt for no lists on wsheet and use the SIMPLE RENAMING (with VBA) no lists required to reduce risk of human error.

+ 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. Excel Dummy Here
    By Innova in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 03-15-2013, 01:09 AM
  2. Using a Dummy Variable
    By chadnchady in forum Excel General
    Replies: 2
    Last Post: 10-01-2012, 09:22 AM
  3. Automatic simple calculation for dummy
    By xavier2000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2007, 09:08 AM
  4. [SOLVED] Excel Dummy - Please Help!
    By Ed in forum Excel General
    Replies: 9
    Last Post: 11-13-2005, 04:10 PM
  5. Question for dummy
    By Yuri Weinstein \(HotMail\) in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-17-2005, 12:05 AM

Tags for this Thread

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