Reference an excel sheet from another workbook without copying the sheet

后端 未结 2 1418
时光说笑
时光说笑 2020-12-11 12:00

Im wondering if it\'s possible to reference an excel sheet from another work book without making a copy of that sheet?

The situation : I have some very large workshe

相关标签:
2条回答
  • 2020-12-11 12:20

    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
    
    0 讨论(0)
  • 2020-12-11 12:21
    =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.

    0 讨论(0)
提交回复
热议问题