+ Reply to Thread
Results 1 to 2 of 2

VBA Code: Recursive File Rename?

Hybrid View

  1. #1
    Registered User
    Join Date
    04-15-2018
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    1

    VBA Code: Recursive File Rename?

    Hello all,

    I'm trying to adapt the below file rename code in order to be able to operate recursively (i.e. perform the operation on all files also found within subfolders of the chosen folder), preferably using File System Object, but I'm having trouble figuring out how to do so.

    Sub RenameFiles()
    Dim xDir As String
    Dim xFile As String
    Dim xRow As Long
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
    If .Show = -1 Then
        xDir = .SelectedItems(1)
        xFile = Dir(xDir & Application.PathSeparator & "*")
        Do Until xFile = ""
            xRow = 0
            On Error Resume Next
            xRow = Application.Match(xFile, Range("A:A"), 0)
            If xRow > 0 Then
                Name xDir & Application.PathSeparator & xFile As _
                xDir & Application.PathSeparator & Cells(xRow, "B").Value
            End If
            xFile = Dir
        Loop
    End If
    End With
    End Sub
    Can anyone provide any guidance? Thank you in advance for any and all help!

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,035

    Re: VBA Code: Recursive File Rename?

    Rule 08: Cross-posting Without Telling Us

    Your post does not comply with Rule 8 of our Forum RULES. Do not cross-post your question on multiple forums without telling us about your threads on other forums.

    Post a link to any other forums where you have asked the same question. If you have fewer than 10 posts here, you will not be able to post a link, but you must still tell us where else you have asked the question.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    No further help to be offered, please, until the OP has complied with this request.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ 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. My File Rename Macro Always Doesn't Rename the Last Three files in the list
    By Enright in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2016, 03:46 PM
  2. VBA Code for file open, read, rename, delete
    By curiosity4learning in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-06-2014, 11:05 AM
  3. [SOLVED] Need a batch file or VBA code to copy and rename a set of workbooks
    By ianpwilliams in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2013, 05:06 AM
  4. Some One Help me write Recursive function on my Code
    By jatin89 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2013, 07:40 PM
  5. Code to rename file and save...
    By Lazypanda in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2009, 06:24 AM
  6. Recursive Code
    By Myles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2006, 02:15 PM
  7. Recursive Code: How does it work?
    By Myles in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2006, 10:28 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