我想开发一种方法来确保从 1 个工作簿 (ThisWorkbook) 复制信息并将其粘贴到另一个工作簿 (All data.xlsm) 的空行中。如果两张工作表在同一个工作簿中,我能够开发代码,但现在我需要参考另一个工作簿,它不起作用(错误 9)。困难还在于两个工作簿都在一个团队站点上,但两个文件都是打开的。请在我的代码下方找到(尽我所能)。
Dim actionlogRow
Dim actionlogRowSet As Boolean
Dim RecordSave As String
Dim recordActionLog As String
actionlogRow = 1
actionlogRowSet = False
Application.ScreenUpdating = False
RecordSave = Range("new_actions").Cells(1, 1).Value
Workbooks("All data.xlsm").Activate
Do
recordActionLog = Worksheets("Action Log").Range("C8:AE8").Offset(actionlogRow, 0).Cells(1, 1)
If recordActionLog = "" Then
'Location to copy to is current row
actionlogRowSet = True
Else
'Look at next row
actionlogRow = actionlogRow + 1
End If
Loop Until actionlogRowSet = True
'Copy the record into the database
Call ThisWorkbook.Sheets("New actions").Range("new_actions_endorsed").Copy
Call Workbooks("All data.xlsm").Worksheets("Action Log").Range("C8:AE8").Offset(actionlogRow, 0).PasteSpecial(xlPasteValuesAndNumberFormats)
Application.ScreenUpdating = True