Using VBA to rename multiple of file names in folder but also taken parts of it out? Would this be possible.

Raboh001

New Member
Joined
May 10, 2022
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
These file names are generally all the same but the numbers being completely different and I am just looking to place a ‘I’ at the start of the file name and removing the numbers at the start of it? The old name would be XS123445567_A_RT_Y 34019 and I would like to rename it too IXS123445567_A_RT_Y instead and I would have around 50 or these files names to change, if anyone has any ideas that would be amazing! Thank you again all
 
It looks like you probably manually typed my code, and missed some comment marks (single quotes) and put carriage returns where they should not be.
Just use Copy and Paste on my code to put it in your workbook. Do not try to manually type the whole thing.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
It looks like you probably manually typed my code, and missed some comment marks (single quotes) and put carriage returns where they should not be.
Just use Copy and Paste on my code to put it in your workbook. Do not try to manually type the whole thing.
Amazing, it worked thank you so much, being cheeky here but just wondering you there is a line of code that could also copy the files in my folder to another file location. Just copy not actually move the original files out of it?.
Thank you again, massive help to me
 
Upvote 0
Amazing, it worked thank you so much, being cheeky here but just wondering you there is a line of code that could also copy the files in my folder to another file location. Just copy not actually move the original files out of it?.
Thank you again, massive help to me
Try this version. Just change the file directories to match your needs:
VBA Code:
Sub MyCopyFiles()

    Dim myDir1 As String
    Dim myDir2 As String
    Dim fn1 As String
    Dim fn2 As String

'   Set directory to look in
    myDir1 = "C:\Temp\Test\"
   
'   Set directory to copy to
    myDir2 = "C:\Temp\Test\New\"
   
    fn1 = Dir(myDir1 & "*.pdf*")
   
'   Loop through files
    Do While fn1 <> ""
'       Check to see that file name does not begin with an "I"
        If Left(fn1, 1) <> "I" Then
'           Build new file name
            fn2 = "I" & Trim(Left(fn1, Len(fn1) - 8)) & ".pdf"
'           Copy file
            FileCopy myDir1 & fn1, myDir2 & fn2
        End If
'       Go to next file
        fn1 = Dir()
    Loop
   
    MsgBox "Copying complete!"
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,099
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top