+ Reply to Thread
Results 1 to 11 of 11

Rename .pdf files in a folder

  1. #1
    Forum Contributor
    Join Date
    01-05-2011
    Location
    India
    MS-Off Ver
    Excel 2013
    Posts
    243

    Rename .pdf files in a folder

    Hi,

    I am looking for a macro to rename the pdf files in a folder.

    Say I have 100 pdf files in a folder 1-100, I need to rename the file to the list I have in excel. For example file name 1 should be renamed to "invoice 1" which I have it in excel spreadsheet. Similarly file name "2" should be renamed to "Invoice 2".

    Please help!

    Regards,
    Vijay
    Last edited by vijanand1279; 04-25-2011 at 05:08 AM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,164

    Re: Rename .pdf files in a folder

    Hi vijanand,

    I'm really into doing things in the easiest manner possible. Have you considered that old program called DOS?
    http://en.wikipedia.org/wiki/List_of_DOS_commands Look for Ren
    http://www.computerhope.com/renamehl.htm

    It it must be done using Excel, look for the Shell command. see
    http://excel.tips.net/T002506_DOS_From_Macros.html
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    01-05-2011
    Location
    India
    MS-Off Ver
    Excel 2013
    Posts
    243

    Re: Rename .pdf files in a folder

    Hi Marvin,

    I have never tried in DOS to rename files. Could you help me with more details on how to perform rename for multiple pdf files in a folder.

    I have hundreds of files which needs to be changed into to invoice number as per the excel list that I have.

    Please help!

    Regards,
    Vijay

    Quote Originally Posted by MarvinP View Post
    Hi vijanand,

    I'm really into doing things in the easiest manner possible. Have you considered that old program called DOS?
    http://en.wikipedia.org/wiki/List_of_DOS_commands Look for Ren
    http://www.computerhope.com/renamehl.htm

    It it must be done using Excel, look for the Shell command. see
    http://excel.tips.net/T002506_DOS_From_Macros.html

  4. #4
    Registered User
    Join Date
    04-18-2011
    Location
    Surrey, UK
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Rename .pdf files in a folder

    Hi Vijay,

    Being the party animal that I am, I decided to make a demo renamer file for you in my lunch-hour yesterday (see attached).

    I recommend making a back-up of the files before you use the spreadsheet, as I have not thoroughly tested it.

    To use the spreadsheet, you copy it into the same folder as all the PDFs that you are wanting to rename.

    When you open it, you will need to put in the list of file names in the columns C and D, as presumably you have some sort of formula/rule or look-up table for naming the new files.

    Once you are happy with the data in columns C and D, click the button over on the top right, and the macro will run.

    The macro reads each PDF file name in the directory that it is copied in, and writes the list of file names in column F. Once this has been done, the macro then goes back to the top of the list, and for each one it does a look-up of the current file name in column C, to read across the new name from column D, then renames the file.

    Note that I have not tested this extensively so there are lots of ways to make the macro fall down. For example, if you have a file in your folder called "3.pdf", and in column C you do not have a file number 3, you will get an "object variable or with block variable not set" error - because the macro is trying to find the number 3 in column C, and cant. This means that you will either have to develop my code to make it more robust, or you will need to make sure that every file name is included in column C.

    Hope this helps.

    Regards,

    Paul
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    01-05-2011
    Location
    India
    MS-Off Ver
    Excel 2013
    Posts
    243

    Re: Rename .pdf files in a folder

    Hi,

    I am getting error.

    Run-Time error '445':

    Object doesn't support this action

    Regards,
    Vijay

    Quote Originally Posted by PaulG2011 View Post
    Hi Vijay,

    Being the party animal that I am, I decided to make a demo renamer file for you in my lunch-hour yesterday (see attached).

    I recommend making a back-up of the files before you use the spreadsheet, as I have not thoroughly tested it.

    To use the spreadsheet, you copy it into the same folder as all the PDFs that you are wanting to rename.

    When you open it, you will need to put in the list of file names in the columns C and D, as presumably you have some sort of formula/rule or look-up table for naming the new files.

    Once you are happy with the data in columns C and D, click the button over on the top right, and the macro will run.

    The macro reads each PDF file name in the directory that it is copied in, and writes the list of file names in column F. Once this has been done, the macro then goes back to the top of the list, and for each one it does a look-up of the current file name in column C, to read across the new name from column D, then renames the file.

    Note that I have not tested this extensively so there are lots of ways to make the macro fall down. For example, if you have a file in your folder called "3.pdf", and in column C you do not have a file number 3, you will get an "object variable or with block variable not set" error - because the macro is trying to find the number 3 in column C, and cant. This means that you will either have to develop my code to make it more robust, or you will need to make sure that every file name is included in column C.

    Hope this helps.

    Regards,

    Paul
    Last edited by arlu1201; 03-19-2013 at 02:49 AM.

  6. #6
    Registered User
    Join Date
    04-18-2011
    Location
    Surrey, UK
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Rename .pdf files in a folder

    Hi Vijay,

    I am sorry that the code does not work for you - what line of code is highlighted when you click "debug"?

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,164

    Re: Rename .pdf files in a folder

    Run CMD from windows to get to a DOS box.
    Change Directory to get to the directory you have all your files (Use the ** dos command)
    At the DOS command prompt type this command

    Please Login or Register  to view this content.
    Press enter and see the magic.

  8. #8
    Registered User
    Join Date
    08-24-2011
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Rename .pdf files in a folder

    Your example file worked PERFECTLY for me, up until I got upgraded to Microsoft Office 2010. Any chance you can walk me through how to adjust? <crosses fingers>

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Rename .pdf files in a folder

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  10. #10
    Registered User
    Join Date
    11-11-2019
    Location
    Philippines
    MS-Off Ver
    none
    Posts
    1

    Re: Rename .pdf files in a folder

    Hi is this VBA creatred on MS Excel.

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,917

    Re: Rename .pdf files in a folder

    Yes it is. Any further questions, please start your own thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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