+ Reply to Thread
Results 1 to 17 of 17

Change files names in a folder

  1. #1
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Change files names in a folder

    Hello everyone,

    I found a code below from the site which is expected to change all files names in a folder by attaching the file modified date to the file name:

    Please Login or Register  to view this content.
    The link is:

    HTML Code: 
    But every time I was trying to run it, it said: Run-time error '53': File not found

    I believe I did follow the procedure properly. Not sure why there is an error like this. I do have files in the folder where the workbook of the macro is saved.

  2. #2
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Change files names in a folder

    Can someone please have a look?

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Change files names in a folder

    try this
    - I have added a few variables to make things easier to follow

    Look in Immediate window to see if you are getting expected results (old name and new name listed together)
    (see immediate window when in VBA editor with {CTRL} G )

    After testing remove the apostrophe to rename the files
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by kev_; 02-01-2019 at 12:07 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  4. #4
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Change files names in a folder

    Hi Key, many thanks for the improved macro. I tried it but it said: Run-time error '5': Invalid procedure call or argument.

    I feel the macro does look good to run. Not sure why there is still error?

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Change files names in a folder

    Try adding this line at the beginning

    Please Login or Register  to view this content.
    You may have some file names without extensions or something

    If that works then I will post more robust update code tomorrow
    (I tested against a folder without subfolders and with perfect files)

    Do not remove the red apostrophe!

  6. #6
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Change files names in a folder

    I tried again but not working

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Change files names in a folder

    Function added to create the new file name
    Before doing so the old file name is checked and bad names are rejected
    Results are written to a new worksheet
    Any rows which are blank in column B are problem names and are excluded from the conversion
    Activate the red line AFTER fully testing!

    Please Login or Register  to view this content.
    Last edited by kev_; 02-02-2019 at 03:32 AM.

  8. #8
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Change files names in a folder

    Hi Kew,

    It is still not working in my case. The GetNewName is indeed able to get valid file names and put them in column A. But after I run the macro, nothing happened in that folder.

    Can you do some test?

  9. #9
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Change files names in a folder

    The code looks amazing. Hopefully it will get working in the end. I don't know where is the problem.

  10. #10
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Change files names in a folder

    Activate the red line AFTER fully testing!
    Did you remove the apostrophe at beginning of this line?
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Change files names in a folder

    I did remove. but nothing happened after the macro. The files still keep the original names.

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Change files names in a folder

    That is peculiar
    - this would happen if the folder does not exist (ie if you are moving files to a new folder)
    - but you are renaming files in the same folder (so the folder path must exist)

    Perhaps the path contains a tiny error.
    Test like this:

    FIRST use File Manager to navigate to the folder
    \ right click on one of the files
    \ click on Properties
    \ Security
    \ look for Object Name and highlight & copy the full path including file name and extension

    NEXT go back to Excel and paste it below the original entry for that file

    Are they IDENTICAL ?

    NEXT look at column B
    - does the new path & file name & extension look correct?

  13. #13
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Change files names in a folder

    Hi Kev_,

    I did more test and finally found the tricky stuff: the macro will run perfectly if "File name extensions" are shown in the windows system. Otherwise, the macro has no effects. It is so wired for Windows

  14. #14
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Change files names in a folder

    Suggest you post your question here https://www.excelforum.com/for-other...mobile-os-etc/
    and name the platform that you are using
    Good luck

  15. #15
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Change files names in a folder

    Thanks, kev_. Your macro is very helpful for a lot of learners like me.

  16. #16
    Registered User
    Join Date
    01-27-2016
    Location
    Belgrade
    MS-Off Ver
    2010
    Posts
    22

    Re: Change files names in a folder

    Hey I need similar thing...

    But I want to in column A import all file names stored in one folder in order they are saver in folder... after that I would in excel and lookup conect old files names with new ones and than with other code I want excel to get new names and rename all files in the folder. Is it possible?

  17. #17
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Change files names in a folder

    Hi sajnica89bg,

    Unfortunately your post does not comply with Rule 4 of our Forum RULES.

    Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    HTH
    Regards, Jeff

+ 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. [SOLVED] change code to get folder names instead of files
    By Ramoi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-14-2018, 08:17 AM
  2. Replies: 1
    Last Post: 02-15-2016, 11:32 AM
  3. [SOLVED] Loop Through Folder, Create Emails with Sub Folder Names in Subject, Attach files in sub
    By Rschwar23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2015, 10:06 AM
  4. Macro for taking names of files in a folder
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-14-2015, 04:27 PM
  5. Import TXT files from a specific folder into Excel - TXT file names change hourly
    By jeepinjeff in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2013, 04:08 AM
  6. Excel Names in column to text files names to folder
    By excelaron in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-17-2013, 07:22 PM
  7. Change names of Files in a folder
    By TISR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2006, 05:45 AM

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