我想知道如何从所有名为“ Table1”的工作簿(除标题之外)中复制内容,然后粘贴到主工作簿上名为“ Table2”的类似格式的表中。
这是我用来更新3200工作簿的代码,我希望再次使用此模板。
我只想复制使用的行(而不是标题),然后将下一个表的值添加到表的底部。
每次保存工作簿时,每个工作簿上的“ Table1”都会记录一些信息。我希望主文件“ 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
我的问题是我不需要标题。我需要为下一张表的数据添加新行。
任何帮助都将不胜感激。谢谢!