Reference an excel sheet from another workbook without copying the sheet

一个人想着一个人 提交于 2019-12-01 13:41:15

Yes, it is possible.

You need to add those lines to your code:

Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet

Set wkb = Excel.Workbooks("name_of_workbook.xlsx")
Set wks = wkb.Worksheets("Example_1")

Now, every time you want to refer to a range from this other workbook, you need to add wks. before, i.e.:

'Printing value in cell.
wks.Range("A1") = "x"

'Selecting range.
call wks.Range(wks.Cells(1,1), wks.Cells(2,2)).Select
=SUM('C:\test\[test.xlsx]sheet_name'!A1:A25)

is an example of a formula which references sheet sheet_name in workbook C:\test\text.xlsx.

Note that when the other workbook is opened, the formula automatically changes to

=SUM([test.xlsx]sheet_name!A1:A25)

and then when it is closed, the formula will change back.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!