Advertisement
verydelonge

rename pdf excel

Apr 3rd, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 0.87 KB | Source Code | 0 0
  1. Sub RenamePDFFiles()
  2.     Dim i As Integer
  3.     Dim sourcePath As String
  4.     Dim oldName As String
  5.     Dim newName As String
  6.    
  7.     'set folder path using input dialog box
  8.    sourcePath = InputBox("Please enter the path to the folder that contains the PDF files:")
  9.    
  10.     'loop through each row in the sheet
  11.    For i = 2 To ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
  12.         'get old and new names from columns B and C
  13.        oldName = sourcePath & ActiveSheet.Range("B" & i).Value & ".pdf"
  14.         newName = sourcePath & ActiveSheet.Range("C" & i).Value & ".pdf"
  15.        
  16.         'rename file
  17.        Name oldName As newName
  18.     Next i
  19.    
  20.     'refresh folder view
  21.    ThisWorkbook.FollowHyperlink sourcePath
  22.     ThisWorkbook.FollowHyperlink "javascript:window.location.reload(true)"
  23.    
  24.     MsgBox "File names have been updated successfully!"
  25. End Sub
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement