0

我想知道如何从所有名为“Table1”(标题除外)的工作簿中复制内容,并将其粘贴到主工作簿上名为“Table2”的类似格式的表格中。

这是我用来更新 3200 工作簿的代码,我希望再次使用这个模板。

我只想复制使用的行(不是标题),然后将下一个表的值添加到表的底部。

每次保存工作簿时,每个工作簿上的“表 1”都会记录一些信息。我希望主“theFILE 1.1.xlsm”在主编辑表上有一个主表(“Table2”)。

Sub Macro2() 

Application.ScreenUpdating = False

Dim sFile As String
Dim wb As Workbook
Dim FileName1 As String
Dim FileName2 As String
Dim wksSource As Worksheet
Const scWkbSourceName As String = "theFILE 1.1.xlsm"

Set wkbSource = Workbooks(scWkbSourceName)
Set wksSource = wkbSource.Sheets("Sheet1") ' Replace Sheet1 with the sheet name

Const wsOriginalBook As String = "theFILE 1.1.xlsm"
Const sPath As String = "E:\theFILES\"

SourceRow = 5

Dim tbl As ListObject
Set tbl = ws.ListObjects("Table2")
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add


Do While Cells(SourceRow, "D").Value <> ""

Sheets("Sheet1").Select

FileName1 = wksSource.Range("A" & SourceRow).Value
FileName2 = wksSource.Range("K" & SourceRow).Value

sFile = sPath & FileName1 & "\" & FileName2 & ".xlsm"

Set wb = Workbooks.Open(sFile)
'''Enter Code for Copy/Paste Tables 

Sheets("EDITS").Visible = True
Sheets("EDITS").Select
ActiveSheet.ListObjects("Table1").Range.Select
'need to omit the header
Selection.Copy

Windows("theFILE 1.1.xlsm").Activate
Sheets("Master Edits").Select
Range("Table2[DATES]").Select
With newrow

    ActiveSheet.Paste

End With

Windows("wb").Activate
Sheets("EDITS").Visible = False

Windows("theFILE 1.1.xlsm").Activate
Sheets("Sheet1").Select



'''CLOSE WORKBOOK W/O BEFORE SAVE
Application.EnableEvents = False
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.EnableEvents = True

SourceRow = SourceRow + 1 ' Move down 1 row for source sheet

Loop

End Sub

我的问题是我不想要标题。我需要为下一个表的数据添加新行。

非常感谢任何和所有帮助。谢谢!

4

0 回答 0