Get a range of cells from a closed workbook in a VBA code run on another workbook

时间:2015-05-04 19:35:51

标签: vba

How do I get a range of cells from a closed workbook in a VBA code run on another workbook?

I am trying the ExecuteExcel4Macro() function. I can not get it to work for a range of more than one cell.

1 个答案:

答案 0 :(得分:0)

我不认为有办法使用ExecuteExcel4Macro访问范围。使用ADO

可能会有更好的结果

你也可以尝试这样的事情:

Sub getARange()
    With Range("A2:B4")
        .Formula = "='C:\[source.xlsx]Input'!A2" 
        .Value = .Value
    End With
End Sub

以上内容会将其复制到您当前的工作簿中。您可能希望执行此类操作或根据您的要求将其存储在范围变量中。