0

我想开发一种方法来确保从 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
4

1 回答 1

0

您必须在同一个 Excel 实例中打开两个电子表格。如果你先打开 Excel,然后从那个(Ctrl O)打开两个电子表格,你应该没问题。但是,如果您打开两个 Excel 程序文件,它们不能互相看到,您将收到“运行时错误 9:下标超出范围”

于 2013-10-29T12:11:22.567 回答