欢迎光临散文网 会员登陆 & 注册

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

2023-07-21 06:51 作者:数字冠军RPA  | 我要投稿

完整代码如下:

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

ChatGPT 和 VBA 的优雅舞蹈:打造智能且高效的办公环境!的评论 (共 条)

分享到微博请遵守国家法律