ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Why doesn't this work...?? (https://www.excelbanter.com/excel-programming/280639-why-doesnt-work.html)

Chris Gorham[_3_]

Why doesn't this work...??
 
Trying to get this piece of code to compile. All I want to
do is to cycle through the range names in a workbook and
assign details to some variables. It bugs out though...

Dim nm as object

For Each nm In ActiveWorkbook.Names

rng_name = nm.Name // this works ok
rng_sheet = nm.Worksheet.Name // this bugs out
rng_add = nm.Address // this also bugs out

Next nm

Any help much appreciated

Chris

Tom Ogilvy

Why doesn't this work...??
 
Dim rng as Range
Dim nm as Name
Dim rng_sheet as String
Dim rng_add as String
Dim nm as Name
For Each nm In ActiveWorkbook.Names

rng_name = nm.Name '// this works ok
On Error Resume Next
set rng = nm.RefersToRange
On Error goto 0
if not rng is nothing then
rng_sheet = rng.parent.Name '// this bugs out
rng_add = rng.Address '// this also bugs out
' or
'rng_add = nm.Refersto
else
rng_sheet = ""
rng_add = ""
end if
Next nm

Regards,
Tom Ogilvy

Note that you can have defined names that don't refer to ranges. That is
what the error checking is all about.

--
Regards,
Tom Ogilvy


Chris Gorham wrote in message
...
Trying to get this piece of code to compile. All I want to
do is to cycle through the range names in a workbook and
assign details to some variables. It bugs out though...

Dim nm as object

For Each nm In ActiveWorkbook.Names

rng_name = nm.Name // this works ok
rng_sheet = nm.Worksheet.Name // this bugs out
rng_add = nm.Address // this also bugs out

Next nm

Any help much appreciated

Chris





All times are GMT +1. The time now is 10:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com