View Single Post
 
Old 05-11-2022, 10:48 AM
ranjan ranjan is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: May 2021
Posts: 80
ranjan is on a distinguished road
Default

Hi,

Below code is not working, could anyone help me in this regards...
Your Help is Highly Appreciated.

I want to remove the _Audited from a all files in the path.

Ex:

Input: 12345_Audited.docx, 455678_Audited.rtf

Output: 12345.docx, 455678.rtf

Code:
Sub BulkRename()
 
    Dim strPath As String
    Dim objFile As file
    Dim objFolder As Folder
    Dim objFSO As Scripting.FileSystemObject
    
   strPath = InputBox("Enter Files Path")
   strPath = strPath & "\"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FolderExists(strPath) Then
        
        Set objFolder = objFSO.GetFolder(strPath)
        
        ' Loop through all files in the folder:
        For Each objFile In objFSO.GetFolder(strPath).Files
           
            If InStr(objFile.Name, "_Audited") = 1 And InStr(objFile.Name, ".docx" ".rtf") <> 0 Then
                '...then copy it with the I removed from the name, overwriting
                ' an existing version, if necessary:
                objFSO.CopyFile objFolder.path & "\" & objFile.Name, objFolder.path & "\" & Mid(objFile.Name, 8), True
               
                objFSO.DeleteFile (objFile.path)
            End If
        Next objFile
    End If
End Sub

Last edited by ranjan; 05-12-2022 at 02:11 AM. Reason: Need to add comment
Reply With Quote