Refer to Excel workbook by path, based on cell value data

前端 未结 3 1622
旧巷少年郎
旧巷少年郎 2021-01-06 02:15

I have an Excel sheet that draws data from other, closed Excel workbooks. Currently it works fine when I list out the closed workbook\'s entire path, but I\'d like to use a

3条回答
  •  误落风尘
    2021-01-06 02:47

    You can store a full reference including the file path to a range in a closed file in a name in excel (either directly or via VBA based on selections in different cells and using the Worksheet_Change procedure as above) and then refer to the file using the name in a formula as normal. This gets over the limitation in the INDIRECT function.

    The VBA is very simple:

    New_Ref = Sheets("Wells").Range("K6")

    ActiveWorkbook.Names("MyWorkbook").RefersTo = "=" & New_Ref

    The only trick is to be sure to include "=" in the name.

    Names have a huge number of uses once you spot this. I have used this to get data from a closed file on a remote sharepoint site without any difficulty - I assume sharepoint deals with all the permissions.

提交回复
热议问题