简体   繁体   中英

Referencing global named range without referencing worksheet

I want to export data from a set of named ranges in workbook x to another set of ranges in workbook y. The names of the ranges to be exported from and to are spesified in a table "Table_Export". Problem is I do not want to spesify in what sheets these respective ranges are located, seeing that I do not know the actual sheet names. But since the ranges are global it should somehow be possible to reference them in vba without referencing the respective worksheet?

The relevant code can be found below where either of the two starred lines within the if statement are what I want to accomplish.

Dim x As Workbook, y As Workbook    
Set x = ThisWorkbook
Set y = Workbooks.Open(Range("Export_to").Value)

Dim export_control As ListObject    
Set export_control = x.Sheets("Control").ListObjects("Table_Export")

Dim lr As Excel.ListRow    
For Each lr In export_control.ListRows
    If lr.Range(1).Value <> 0 Then    
        *'y.Names(lr.Range(2).Value).RefersToRange.Value = x.Names(lr.Range(1).Value).RefersToRange.Value*    
        *'y.Range(lr(Range(2).Value).Value = x.Range(lr(Range(1).Value).Value*    
    End If
Next

使用相应工作簿对象的“属性名称 ”来引用“全局名称”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM