So I wanna update file names using power Query. I have created a table with my old file name and new file name using power query. However, I wanna know how I can automate this using Power Query and Excel. I used this guide How to rename all the files in a folder using Excel VBA? - Free Excel Tips & Tricks | Free Excel VBA Code however when I use the macro all i get is an error. Here is the code I used
VBA Code:
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\Username\Desktop\FolderWithUnformatedFiles)"
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
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