To elaborate, let's say I have two named ranges in my workbook. Both named ranges have the same Name (let's say "myName"), but one is scoped to Sheet1 and the other is scoped to the Workbook.
Given a name (string) of the Named Range, I want to grab the Workbook level Named Range.
If I use the native call: wb.Names.Item("myName")
, it returns the sheet scoped named range.
If instead I do: wb.Names.Item("Sheet1!myName")
, that obviously returns the sheet scoped name range. I've found I can use this to specify the sheet specific ones, but not a workbook one.
Is there anyway I can specify I want the workbook scoped one?
My workaround is currently iterating over the list of all the Names, and comparing the .Name property to grab the workbook scope Named Range. This works because the .Name property appends a "Sheet1!" to the sheet scoped Named Range. This is however very costly to do, and I want to avoid it.
Set rng1 = Range("myName")
will return the range from the local sheet name if sheet1 is active else it will return the range from the workbook name. I think this is the cleanest workaround - ie test that the active sheet is different from the sheet hosting the local name before looking to use the name as the workbook scope. Make sense? :) – Wil