Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub RenamePDFFiles()
- Dim i As Integer
- Dim sourcePath As String
- Dim oldName As String
- Dim newName As String
- 'set folder path using input dialog box
- sourcePath = InputBox("Please enter the path to the folder that contains the PDF files:")
- 'loop through each row in the sheet
- For i = 2 To ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
- 'get old and new names from columns B and C
- oldName = sourcePath & ActiveSheet.Range("B" & i).Value & ".pdf"
- newName = sourcePath & ActiveSheet.Range("C" & i).Value & ".pdf"
- 'rename file
- Name oldName As newName
- Next i
- 'refresh folder view
- ThisWorkbook.FollowHyperlink sourcePath
- ThisWorkbook.FollowHyperlink "javascript:window.location.reload(true)"
- MsgBox "File names have been updated successfully!"
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement