工作簿之间的VBA复制行

时间:2017-08-18 10:55:25

标签: excel vba excel-vba copy

我正在寻找如何在exel中完成我的任务的想法。 情况: 有两本工作簿--A和B. 我需要将特定数据从A复制到B. 有些数据是静态的 - 大概是好的,我用这段代码复制它 -

Sub Button399_Click()
    Dim sutartis As String
    Dim projektoID As String
    Dim projektas As String
    Dim Aktas As Workbook

    Worksheets("Aktas").Select
    sutartis = Range("K4")
    projektoID = Range("K5")
    projektas = Range("E12")
    Set myData = Workbooks.Open("*****")
    Worksheets("Archyve").Select
    Worksheets("Archyve").Range("A1").Select
    RowCount = Worksheets("Archyve").Range("A1").CurrentRegion.Rows.Count

    With Worksheets("Archyve").Range("A1")
        .Offset(RowCount, 0) = sutartis
        .Offset(RowCount, 1) = projektoID
        .Offset(RowCount, 2) = projektas
    End With

    myData.Save
End Sub

其次,我需要从每一行复制数据,并在每行中添加静态的B工作簿。 check the list

结果,它应该如下所示: result

等待所有建议和想法!

祝你好运

1 个答案:

答案 0 :(得分:0)

以下函数从已关闭的工作簿中检索数据。 信用 http://erlandsendata.no/?p=2106

Private Function GetInfoFromClosedFile(ByVal wbPath As String, wbName As String, wsName As String, cellRef As String) As Variant
    Dim arg As String
    GetInfoFromClosedFile = vbNullString
    If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
    If Dir(wbPath & wbName) = vbNullString Then Exit Function
    arg = "'" & wbPath & "[" & wbName & "]" & wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
    'On Error Resume Next
    GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
End Function