1. 程式人生 > >複製其他Excel檔案的sheet到本Excel檔案中

複製其他Excel檔案的sheet到本Excel檔案中

在.xlsm檔案中開啟Visual Basic編輯器,在文字編輯器中輸入以下VBA程式,實現複製sheet功能。

Private Sub all2here_Click()    '其他sheet表複製到此Excel中
    MsgBox "歡迎開始載入……"
    Dim wb, arr, Sh As Worksheet, pic As Shape
    Application.ScreenUpdating = False

     '1號庫A班
     Path = Application.ThisWorkbook.Path    '相對路徑
     Set wb = Workbooks.Open(Filename:=Path & "\自營考勤8月份\1號庫A班\" & "1號庫A班.xlsx", UpdateLinks:=0)
       For Each Sh In wb.Worksheets
          If Sh.Name = "員工考勤表" Then
                Sheets("員工考勤表").Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)   '複製年休假明細表;
                ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = "1號庫A班考勤合同"
            End If
        Next
     wb.Close False

   Application.ScreenUpdating = True
   MsgBox "載入完成結束!"
End Sub