ChatGPT 和 VBA 的优雅舞蹈:打造智能且高效的办公环境!

完整代码如下:
Sub ReplaceTextInFiles()
Dim wb As Workbook
Dim ws As Worksheet
Dim strFolder As String
Dim strFile As String
Dim strOutFolder As String
Application.ScreenUpdating = False
Application.EnableEvents = False
strFolder = "C:\Users\Administrator\Desktop\DEMO\Input\"
strOutFolder = "C:\Users\Administrator\Desktop\DEMO\Output\"
strFile = Dir(strFolder & "*.xls*")
Do While strFile <> ""
' Open workbook
Set wb = Workbooks.Open(Filename:=strFolder & strFile)
' Loop through each worksheet
For Each ws In wb.Worksheets
' Replace text
ws.Cells.Replace What:="Order Number", Replacement:="订单号", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ws.Cells.Replace What:="Customer Name", Replacement:="客户名", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next ws
' Save and close workbook in the Output folder
wb.SaveAs Filename:=strOutFolder & wb.Name
wb.Close SaveChanges:=False
' Get next file
strFile = Dir
Loop
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub