'This method renames all the filenames in a folder Sub RenameAllFilenamesInAFolder() Dim intRowCount As Integer Dim intCtr As Integer Dim strFileNameExisting As String Dim strFileNameNew As String Dim strFolder As String
'Set the folder path
strFolder = "C:\Users\rchandramohan\"
With Sheet1
'Find the total rows count in the sheet
'This will be the last non-blank cell in column A...
intRowCount = .Cells(.Rows.Count, "A").End(xlUp).Row
'Loop through from the 2nd row (1st row is Heading)
'till the total rows in the sheet
For intCtr = 2 To intRowCount
'Get the existing filename from the cell
strFileNameExisting = .Range("A" & intCtr)
'Get the new filename from the cell
strFileNameNew = .Range("B" & intCtr)
'Rename the file
** Name strFolder & strFileNameExisting As strFolder & strFileNameNew **
Next intCtr
End With
'Display an appropriate message, once complete
MsgBox "All files renamed successfully!", _
vbInformation, "All files renamed"
End Sub
Hi, I need a help, I am using the above code for renaming the files in a folder, I am getting the syntax error in the line where I have marked ** before and after the particular line, Name strFolder & strFileNameExisting As strFolder & strFileNameNew
I am new to this macro and I could not find it out where the mistake is. Please looking for the solution.
Name
? – StoraxstrFileNameNew
a valid Windows file name? – Tim Williams