Getting a range from a closed workbook into an array

后端 未结 2 1406
梦如初夏
梦如初夏 2021-01-07 09:16

How do I get a range of data from a closed workbook into an array in VBA? Preferably without opening the workbook.

Thanks

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 09:56

    If you're only interested in the data values in the closed workbook, you can use an empty range of your open workbook as a scratch area and then fill that range with an array formula:

    ScratchWorksheet.Range("B1", "B3").FormulaArray = "='PathToClosedBook\[ClosedBook.xlsx]Sheet1'!$B$1:$B$3"
    

    After you're finished you can delete the FormulaArray so you don't leave external links in the open workbook.

提交回复
热议问题