![]() |
Range Object Question
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 |
Range Object Question
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 |
Range Object Question
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 |
All times are GMT +1. The time now is 05:36 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com