Using Excel VBA to rename files in directory FOLDER TYPE

ferrariako

New Member
Joined
May 5, 2013
Messages
16
I know this question has been asked before... my problem is very similar to this http://www.mrexcel.com/forum/excel-...asic-applications-rename-files-directory.html...

and the solution we got from there looks like this:

Sub List_Files()
Dim MyFolder As String
Dim MyFile As String
Dim a As Integer
MyFolder = "C:\DealerExam\" ' <-- Change to your folder
MyFile = Dir(MyFolder & "*.*")
a = 0
Do While MyFile <> ""
a = a + 1
Cells(a, 1).Value = MyFile
MyFile = Dir
Loop
MsgBox "You may now list your new names for each file in Column 'B'." & vbCr & vbCr & _
"All cells must have valid file name. Run 'ReName_Files' Sub when ready."

End Sub


Sub ReName_Files()

Dim r As Integer
r = 1
Do Until IsEmpty(Cells(r, "A")) Or IsEmpty(Cells(r, "B"))
Name Cells(r, "A") As Cells(r, "B")
r = r + 1
LoopMsgBox "All your old file names in Column 'A' have been reNamed" & vbCr & _
"to the adjacent new name in column 'B'."

End Sub

now this code works fine for most of the file extension type, it just so happens the the first method can't get the file names for FOLDER types... I want to rename the FOLDERS not files... thanks in advance
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

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