How to rename files of a Folder using VBA


It is easy and convenient to rename files of a folder using VBA. This can be accomplished with few lines of code. To do this, First you need to have fully qualified path with Names of the files and the new Names of those file to which you want to rename it to. Organize this data into two different columns as shown below.

















Now, copy paste the below VBA code into VBEditor and run the program. The file names of files 1,2,3,4 and 5 gets converted into A, B, C D and E respectively.

Sub FileRename()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim n As String
Dim m As String
Dim RowCount As Integer

Sheets("Sheet1").Select
RowCount = Application.WorksheetFunction.CountA(Range("A:A"))

For i = 2 To RowCount
 n = Cells(i, 1)
 m = Cells(i, 2)
 Workbooks.Open (n)
 ActiveWorkbook.SaveAs (m)
 ActiveWorkbook.Close
 Kill (n)
 ThisWorkbook.Save
Next
End Sub


Here is a video demonstration to the above Example.


Use Coupon Code 580EDUNF83 to get additional 20% discount








Share:

0 comments:

Post a Comment