Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 05-11-2022, 10:48 AM
ranjan ranjan is offline Bulk File Rename Windows 10 Bulk File Rename Office 2019
Advanced Beginner
Bulk File Rename
 
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
 

Tags
bulk, rename file



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk File Rename Rename file when sending emmanpelayo Word VBA 1 09-28-2016 10:05 PM
Rename visio file & hyperlink O'Neill Visio 0 05-08-2016 11:43 PM
Save and rename attachments from ZIP FILE AndyDDUK Outlook 1 03-03-2016 12:32 AM
Bulk File Rename Rename File cksm4 Word VBA 2 02-25-2011 09:29 AM
How would I bulk select and copy highlights and then bulk paste them automatically? copywriterpro Word 0 04-19-2010 05:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft