简体   繁体   English

打开工作簿和复印表

[英]Open workbooks and copy sheets

I need help with a macro that will open workbooks in the same folder and copy the Whole sheet in each workbook to a workbook where my macro is at. 我需要一个宏的帮助,该宏将在同一文件夹中打开工作簿并将每个工作簿中的整个工作表复制到我的宏所在的工作簿中。

There are 4 different workbooks and they all have a different number of sheets and I need to have all the sheet from each workbook in one. 有4种不同的工作簿,它们都有不同数量的工作表,我需要将每个工作簿中的所有工作表都放在一个工作表中。

I just started programming and get and error object required 424 on the line that says: Set wsSheet = wbRegularesBruto.Sheets("Movimentacao").Cells.Copy 我刚刚开始编程,并在显示以下内容的行上获取并请求了错误对象424:Set wsSheet = wbRegularesBruto.Sheets(“ Movimentacao”)。Cells.Copy

Can someone please guide me to resolve this issue. 有人可以指导我解决此问题。 Does anyone know of an easier way to get all these sheets copied into the TH Macro Workbook? 有谁知道将所有这些表复制到TH Macro Workbook的简便方法?

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
Set wsSheet = wbRegularesBruto.Sheets("Movimentacao").Cells.Copy

wsSheet is a Worksheet object. wsSheet是一个工作表对象。 I assume you want to assign it to this sheet, so you would use: 我假设您想将其分配给此工作表,因此可以使用:

Set wsSheet = wbRegularesBruto.Sheets("Movimentacao")

You could then use Cells.Copy after this. 然后,您可以在此之后使用Cells.Copy You can't do both in one statement. 您不能在一项声明中同时做到这两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM