我需要一个宏的帮助,它将在同一个文件夹中打开工作簿,并将每个工作簿中的整个工作表复制到我的宏所在的工作簿。
有4种不同的工作簿,它们都有不同数量的工作表,我需要将每个工作簿中的所有工作表合二为一。
我刚刚开始编程并获取和错误对象所需的424行: 设置wsSheet = wbRegularesBruto.Sheets(" Movimentacao")。Cells.Copy
有人可以指导我解决此问题。有没有人知道将所有这些工作表复制到TH宏工作簿中的更简单方法?
Option Explicit
Sub TrainingHoursMacro()
Dim wbTHMacro As Workbook, wsRegulares As Worksheet, wsRegularesDemitidos As Worksheet, wsTempActivos As Worksheet, wsTempJA As Worksheet, wsTempFit As Worksheet, _
wsTempDemitidos As Worksheet, wsPresenceSystem As Worksheet, wsResultados As Worksheet, wsDLList As Worksheet, wsSheet As Worksheet
Dim wbRegularesBruto As Workbook, wsMovimentacao As Worksheet, wsDemitidos As Worksheet
Dim wbTemporariosBruto As Workbook, wsTemporariosAtivos As Worksheet, wsJAAtivos As Worksheet, wsAprendizesFit As Worksheet
Dim wbPresenceSystem As Workbook, wsTPCC As Worksheet
Set wbTHMacro = Workbooks("Training Hours Macro.xlsm")
Set wsRegulares = wbTHMacro.Sheets("Regulares")
wsRegulares.Cells.ClearContents
Set wbRegularesBruto = Workbooks.Open(Filename:="H:\BX-HR\BX-INDUSTRIAL RELATIONS\HR REPRESENTATIVES\PRIVATE\HRSSC\Brazil\Training Hours Macro\Regulares Bruto.xls")
If Not wbRegularesBruto Is Nothing Then
Set wsSheet = wbRegularesBruto.Sheets("Movimentacao").Cells.Copy
wsSheet.Cells.Copy wsRegulares.Range("A1")
Else
Exit Sub
End If
End Sub
答案 0 :(得分:1)
Set wsSheet = wbRegularesBruto.Sheets("Movimentacao").Cells.Copy
wsSheet
是一个Worksheet对象。我假设您要将其分配给此工作表,因此您将使用:
Set wsSheet = wbRegularesBruto.Sheets("Movimentacao")
然后您可以在此之后使用Cells.Copy
。你不能在一个声明中做到这两点。