Closed Thread
Results 1 to 34 of 34

Using Macro, how to rename the Filenames in an Folder

  1. #1
    Registered User
    Join Date
    09-13-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    13

    Thumbs up Using Macro, how to rename the Filenames in an Folder

    Hi Excel Team,

    I need help from ur End, I need tht How to rename the Filenames in an Folder using macro.. Is it possible, How we can do it..

    Example:
    In an Folder 200files are there with extenxion .jpg/xls/bmp/txt/doc files, I want to rename tht those files names,

    Example1:
    Source File: TestImage.jpg
    I want rename as
    Destination file : image.jpg.


    Not only Single file rename..if i wnt to rename Bulk means?...

    Is there any coding is there, Can any one share it, its More helpful.........

    Waiting For ur rply..

    Regards,
    Karthick
    Last edited by Karthik@1305; 09-23-2010 at 12:30 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    Hi Karthik@1305,
    Welcome to the forum.
    A good place to start is with this altered code by Julitta Korol
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    09-13-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Using Macro, how to rename the Filenames in an Folder

    Thanks pike, But My Requirement is i want rename to more than 100files, this code is Used for Only Single file renaming, But i Need to rename Morethan 100 files..If possible can u Send Me Coding related to my requirement, Its More Helpful...


    Thank you Pike

    Regards
    Karthick












    Quote Originally Posted by pike View Post
    Hi Karthik@1305,
    Welcome to the forum.
    A good place to start is with this altered code by Julitta Korol
    Please Login or Register  to view this content.

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    Hi Karthik@1305
    There is no need to quote my posts in yours; it just cluters the threads.
    you wont be able to rename then all "image" is is it just the ones named
    TestImage?

  5. #5
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Re: Using Macro, how to rename the Filenames in an Folder

    Hi Pike,

    Thanks for sharing the code for renaming files, but for a better understanding Can you tell me the above code will search the folder in which folder as we are not mentioning any folder path here ? In case if we want to search & rename files in a specific folder only , How can we do that ?

    Hope I am not asking too much. Actually I am also looking for such possibility.

    Regards,
    Daksh
    I am still a learner.

  6. #6
    Registered User
    Join Date
    09-13-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Using Macro, how to rename the Filenames in an Folder

    Hi Pike,

    Sorry Pike, Iam new to this Forum, So i don't Know how to rply, thts why i made mistake, sorry don't mind, Can u tell me Solution For my Problem,

    How to rename all Image Files at a time.......

    Regards
    Karthick

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Macro, how to rename the Filenames in an Folder

    Please Login or Register  to view this content.
    PS what do 'tht', rply', 'thts', 'u' mean ?
    Can you please write in plain English ?
    Last edited by snb; 09-22-2010 at 04:31 AM.



  8. #8
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    Hi Karthik@1305

    I'll like this way..

    Please Login or Register  to view this content.

  9. #9
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    Hi snb,
    Have you tested your code?

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Macro, how to rename the Filenames in an Folder

    Yes, that's why I changed it a little bit.

  11. #11
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    Have you tried testing it and found an error with "rename"?

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Macro, how to rename the Filenames in an Folder

    @Pike,

    Thank you...

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Re: Using Macro, how to rename the Filenames in an Folder

    Pike and snb thanks to both of you these codes are really awesome.

  14. #14
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    this will be better as if the file exist the code wont err
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    09-13-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Using Macro, how to rename the Filenames in an Folder

    Thanks you @ Pike and @snb, thanks alot.. now its working fine....... thanks..... keep in touch.. Take care

    Regards
    Karthick

  16. #16
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Macro, how to rename the Filenames in an Folder

    @Pike
    I don't think
    Please Login or Register  to view this content.
    serves any purpose.

    And why 2 tests for checking whether a file exists ?

  17. #17
    Registered User
    Join Date
    09-13-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Using Macro, how to rename the Filenames in an Folder

    @snb, I need more thing, i want to select source file and Destination File,and then Rename it.. is it Possible...

    Actually i tell u My requirement is...

    We Extracted Datas(Filenames) from SAP and it downloaded to Excel Sheet, i need to rename tht filesname,,,

    Example:

    Source Destination(I need to Rename)
    TRSTVON.ipg ZJIRJR5400054.jpg

    like this iam having 200 files and more files...
    i want to rename it.... Is it possible, any code is there to rename.........if possible send me a code........

    regards
    Karthick

  18. #18
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Macro, how to rename the Filenames in an Folder

    Please Login or Register  to view this content.

  19. #19
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    Hi snb
    I delcare all variables ect and chdir is good housekeeping as it is for default directory but not the default drive

    The file check is just in case the file already exist - image #

    where i can see a problem with not checking using "replace" is if IF you have files
    imagetest and testimage. This will cause error

    But the replace code has changed with/as the op request is growing

  20. #20
    Registered User
    Join Date
    09-13-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Using Macro, how to rename the Filenames in an Folder

    thanku @snb, Sorry to ask again, actually all Datas from SAP Downloaded in to Excel(Sheet1), Using tht Sheet1(Dispalyed all filenames), Now i have to Rename tht file,

    Example, In Excel Sheet1,

    DMSNO Filename

    500000678 TCVXPN91.jpg
    500000675 TCVXPN92.jpg
    500000677 TCVXPN93.jpg
    500000674 TCVXPN94.jpg
    500000675 TCVXPN95.jpg

    Now i have to rename tht File Name From 'TCVXPN92.jpg' Rename To: 'RJRV500000675.jpg'

    After this I have check it in Source Folder, wheather tht name is changed or not.......

    Is it Possible, If possible guide me how to do, If possible send me a code........

    Regards
    Karthick

  21. #21
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Macro, how to rename the Filenames in an Folder

    If you select a directory, using

    Please Login or Register  to view this content.
    It doesn't matter which directory is the currentdirectory.
    If a folder is specified in Dir(..) it acts independent of CurDir.

    So in your code :
    Please Login or Register  to view this content.
    do not contribute to the correct functioning of the macro.
    Good housekeeping is fine, preventing a 'messy' house is better.

  22. #22
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    Hey snb
    good habbit when when you have heaps of drives / directory
    yes the \ is not needed ..well spotted
    Please Login or Register  to view this content.

  23. #23
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Macro, how to rename the Filenames in an Folder

    @Karthick

    It seems to me preferable to describe the whole process you are working on.
    Now you are asking very partial questions, that can only be answered partially. I wonder whether you are adapting the given code. Based on the given suggestions you should be able to modify the code (even your Excel version has some help-files in the VBEditor).

  24. #24
    Registered User
    Join Date
    09-13-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Using Macro, how to rename the Filenames in an Folder

    @snb, Thank you..........

    Regards
    Karthick

  25. #25
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using Macro, how to rename the Filenames in an Folder

    @Pike,

    You'r missing my point, you macro can be written like:

    Please Login or Register  to view this content.

  26. #26
    Registered User
    Join Date
    09-13-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Using Macro, how to rename the Filenames in an Folder

    @snb, Its not runinng, i didn't get any Output,So can u send me extact code to rectify my problem.......


    Regards
    Karthick

  27. #27
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    Hi Karthik@1305,
    you will need to expand on what you mean its vague - which code?-
    Also if your first question is solved please mark the post solved. If you have additional questions please start a new thread.

    Hey snb, yes it can be written that way. I like to get ensure everything is set back to the way it was.

  28. #28
    Registered User
    Join Date
    09-13-2010
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Using Macro, how to rename the Filenames in an Folder

    SOLVED
    Thank you @pike @snb

  29. #29
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Last edited by pike; 09-23-2010 at 12:28 AM.

  30. #30
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  31. #31
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Using Macro, how to rename the Filenames in an Folder

    Thanks for taking the time to read and comply with the rule .

  32. #32
    Registered User
    Join Date
    08-31-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Using Macro, how to rename the Filenames in an Folder

    In case anybody else is looking for this here is the code (used some code from other forum and adjusted as needed; make sure to have a worksheet with 2 columns - old name and new name i.e. sample1.jpg -- renamedsample1.jpg; save the files to appropriate folder on C drive):

    Sub Rename()


    Dim strPath As String
    Dim strOldName As String
    Dim strNewName As String

    p = Range("A65000").End(xlUp).row

    strPath = "C:\Picture\"

    Range("B1").Select

    Do Until ActiveCell.row = p

    ActiveCell.Offset(1, -1).Select
    strOldName = ActiveCell.Value
    ActiveCell.Offset(0, 1).Select
    strNewName = ActiveCell.Value

    Name strPath & strOldName As strPath & strNewName

    Loop

    p = Range("A65000").End(xlUp).row

    End Sub

  33. #33
    Registered User
    Join Date
    09-17-2014
    Location
    kathmandu,Nepal
    MS-Off Ver
    office 2007
    Posts
    2

    Re: Using Macro, how to rename the Filenames in an Folder

    Hi dear,

    I have thousands of files in a folder in different formats .jpg,.wav,.mp3,.pdf,.rar,.xlsx,.csv,etc and arranging those files in 100s of folders,creating and renaming them is just taking lot of time . I spend days in it creating folder, renaming and copying those files in their respective folders . Its been 4 days since i've been googling for my solution and i found similar queries in net and i even looked at those solved problem but non of them worked for me, most of them were vba macros. Finally here i am with my problem discussing with you. What i need is a macros that could create the folders i need, rename my files as per excel list and copy those files to folders as per excel list. i have not reported my work in 5 days tomorrow is my final day of reporting and my work is **** and i have nothing.If not possible macro for copying and renaming would also be good enough for me. Hope i get respond of my post ASAP or i'm in trouble. I have attached a sample with this mail plzzzz anyone helpppppppppppp.

    Thank You.

  34. #34
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Using Macro, how to rename the Filenames in an Folder

    Pls start your own thread as per forum rules.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

Closed 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