Sub Ex()
Dim Path As String, A As String, Oldname As String, Newname As String
Path = ThisWorkbook.Path '路徑
A = Dir(Path & "\*.CSV")
Do While A <> ""
Oldname = Path & "\" & A
A = Replace(A, "基準日:", "")
A = "539_" & A '新增需求:再將檔案名稱前批改增加 "539_"
A = Replace(A, ".csv", ".xls")
Newname = Path & "\" & A
'Name Oldname As Newname '改名稱
With Workbooks.Open(Oldname)
.SaveAs Filename:=Newname, FileFormat:=xlNormal '改副檔案名
.Close True
End With
Kill Oldname
A = Dir
Loop
End Sub
Option Explicit
Sub Ex()
Dim oPath As String, A As String, Oldname As String, Newname As String
Application.ScreenUpdating = False
oPath = ThisWorkbook.Path '路徑
A = Dir(oPath & "\*.CSV")
Do While A <> ""
Oldname = oPath & "\" & A
A = Replace(A, "基準日:", "")
A = "539_" & A '新增需求:再將檔案名稱前批改增加 "539_"
A = Replace(A, ".csv", ".xls")
Newname = oPath & "\" & A
With Workbooks.Open(Oldname)
.Sheets(1).Name = Replace(A, ".xls", "")
.SaveAs Filename:=Newname, FileFormat:=xlNormal '改副檔案名
.Close True
End With
Kill Oldname
A = Dir
Loop
End Sub