Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This may be more of an Excel Object/VBA question, but here goes...
I am working on a VSTO excel project, being developed in version 2003. I am running through a series of excel Range Objects that are named ranges in a workbook. Is there a way to identify the Name of the range in code? I have a data mappings page that ties the ranges to a custom Object's properties and I need to grab the Name associated with the active range/cell so I can shove it in the object. Any tips would be great. thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
selection.Name.Name (range object.Name returns a Name object )
if it doesn't have a name, you get an error. the selection must represent the entirety of the cells in the range - for example if the Selection is A1 and the range A1:B2 is named Horse, then you would get an error. If the selection in A1:B2, then it would return Horse. This is how I would do it in VBA: Sub TestName() Dim nm As Name On Error Resume Next Set nm = Selection.Name On Error GoTo 0 If Not nm Is Nothing Then MsgBox nm.Name Else MsgBox "no name" End If End Sub -- Regards, Tom Ogilvy "abillmeier" wrote in message ... This may be more of an Excel Object/VBA question, but here goes... I am working on a VSTO excel project, being developed in version 2003. I am running through a series of excel Range Objects that are named ranges in a workbook. Is there a way to identify the Name of the range in code? I have a data mappings page that ties the ranges to a custom Object's properties and I need to grab the Name associated with the active range/cell so I can shove it in the object. Any tips would be great. thanks |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for the assist, works great.
"Tom Ogilvy" wrote in message ... selection.Name.Name (range object.Name returns a Name object ) if it doesn't have a name, you get an error. the selection must represent the entirety of the cells in the range - for example if the Selection is A1 and the range A1:B2 is named Horse, then you would get an error. If the selection in A1:B2, then it would return Horse. This is how I would do it in VBA: Sub TestName() Dim nm As Name On Error Resume Next Set nm = Selection.Name On Error GoTo 0 If Not nm Is Nothing Then MsgBox nm.Name Else MsgBox "no name" End If End Sub -- Regards, Tom Ogilvy "abillmeier" wrote in message ... This may be more of an Excel Object/VBA question, but here goes... I am working on a VSTO excel project, being developed in version 2003. I am running through a series of excel Range Objects that are named ranges in a workbook. Is there a way to identify the Name of the range in code? I have a data mappings page that ties the ranges to a custom Object's properties and I need to grab the Name associated with the active range/cell so I can shove it in the object. Any tips would be great. thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Range Question / error 1004: method Range of object Worksheet has failed | Excel Programming | |||
returning pivottable object from a range object | Excel Programming | |||
Range object to Array object conversion | Excel Programming | |||
Range object to Array object conversion | Excel Programming | |||
Range object to Array object conversion | Excel Programming |