Sorry, must be <ID>_BSC393588_BCF14_<DATA>.xlsPls explain
How 21783_BSC393588_BCF14.xls became <ID>_BSC393588_<DATA>.xls
where's the bold part gone.
Sorry, must be <ID>_BSC393588_BCF14_<DATA>.xlsPls explain
How 21783_BSC393588_BCF14.xls became <ID>_BSC393588_<DATA>.xls
where's the bold part gone.
Option Explicit
Sub rename_5()
Dim NewName As String, mydir As String, objFile As Object
Dim Last_name As String, id As String
mydir = Application.ThisWorkbook.Path
id = Range("e2").Value
With CreateObject("Scripting.FileSystemObject")
For Each objFile In .GetFolder(mydir).Files
Last_name = Mid(objFile.Name, _
InStrRev(objFile.Name, "_") + 1, InStrRev(objFile.Name, ".") - _
InStrRev(objFile.Name, "_") - 1)
NewName = Replace(objFile.Name, Last_name, Last_name & "_" & Format(Date, "YYYYMMDD"))
NewName = Replace(NewName, id, "")
NewName = id & "_" & NewName
On Error Resume Next
Name objFile As Replace(objFile, objFile.Name, NewName)
On Error GoTo 0
N: Next
End With
MsgBox "Done"
End Sub
Check this...
Code:Option Explicit Sub rename_5() Dim NewName As String, mydir As String, objFile As Object Dim Last_name As String, id As String mydir = Application.ThisWorkbook.Path id = Range("e2").Value With CreateObject("Scripting.FileSystemObject") For Each objFile In .GetFolder(mydir).Files Last_name = Mid(objFile.Name, _ InStrRev(objFile.Name, "_") + 1, InStrRev(objFile.Name, ".") - _ InStrRev(objFile.Name, "_") - 1) NewName = Replace(objFile.Name, Last_name, Last_name & "_" & Format(Date, "YYYYMMDD")) NewName = Replace(NewName, id, "") NewName = id & "_" & NewName On Error Resume Next Name objFile As Replace(objFile, objFile.Name, NewName) On Error GoTo 0 N: Next End With MsgBox "Done" End Sub
Hi,It is working without errors, but once again does not work on some occasions,
No worries I really appreciate everything! Thanks again
It WorkedCheck this...
Code:Option Explicit Sub rename_3() Dim NewName As String, mydir As String, objFile As Object mydir = Application.ThisWorkbook.Path With CreateObject("Scripting.FileSystemObject") For Each objFile In .GetFolder(mydir).Files If InStrRev(objFile.Name, "_") Then NewName = Replace(objFile.Name, Mid(objFile.Name, _ InStrRev(objFile.Name, "_") + 1, InStrRev(objFile.Name, ".") - _ InStrRev(objFile.Name, "_") - 1), Format(Date, "YYYYMMDD")) Name objFile As Replace(objFile, objFile.Name, NewName) End If Next End With MsgBox "Done" End Sub