Hello I need to generate a code that renames all files in a folder that start with "report" to "X-CT". The remainder of the filename, including the ".DOC .PDF. XLS" filing continued unchanged.
Hello I need to generate a code that renames all files in a folder that start with "report" to "X-CT". The remainder of the filename, including the ".DOC .PDF. XLS" filing continued unchanged.
Maybe the code below will help you. Basically, it loops through the files of a directory and replaces, in the name of each file, the string of characters you want to replace with the new one.
Follow the code with the @Evert:
Sub changeFileName(ByVal srtExtencion as String)
Dim strFolder As String
Dim strFile As String
strFolder = "C:\SomeFolder\"
strFile = Dir(strFolder & "\*." & strExtension)
Do While Len(strFile) > 0
If InStr(strFile, "relat") > 0 Then
Name strFolder & strFile As strFolder & Replace(strFile, "relat", "X-CT")
End If
strFile = Dir()
Loop
End Sub
Then call the function with the desired extension:
changeFileName doc
changeFileName pdf
changeFileName xls
Extract this solution from this forum alongside the user-submitted edition @ Evert