Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My macro creates new shapes on the worksheet.
I want to group them but if no shapes were created the macro fails. How do I test for valid selection. I have tied: If Not Selection Is Nothing Then Selection.ShapeRange.Group If Not Selection.ShapeRange Is Nothing Then Selection.... But nothing works. It says "Object doesn't support this property or method" Thanks *** Sent via Developersdex http://www.developersdex.com *** |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Maybe you could use a shape object to test if at least one shape exists
on the sheet eg: Dim shp As Shape On Error Resume Next Set shp = ActiveSheet.Shapes(1) On Error GoTo 0 If Not shp Is Nothing Then MsgBox "Do this" Else MsgBox "exit" End If Hope this helps Rowan Edward Ulle wrote: My macro creates new shapes on the worksheet. I want to group them but if no shapes were created the macro fails. How do I test for valid selection. I have tied: If Not Selection Is Nothing Then Selection.ShapeRange.Group If Not Selection.ShapeRange Is Nothing Then Selection.... But nothing works. It says "Object doesn't support this property or method" Thanks *** Sent via Developersdex http://www.developersdex.com *** |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Rowan,
I was trying to avoid error handling. I thought a simple property check would do it. See my response to Norman. Thanks. Ed *** Sent via Developersdex http://www.developersdex.com *** |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Edward,
Problems will also arise if there are less than 2 shapes or less than 2 existing groups of shapes. Try something like: '==================== Sub TestIt() Dim sr As ShapeRange With ActiveSheet.Shapes .SelectAll Selection.Ungroup If .Count = 2 Then .SelectAll Set sr = Selection.ShapeRange sr.Group ' Else 'Less than 2 shapes exist, do something, e.g.: MsgBox "The number of shapes = " & .Count End If End With If Not sr Is Nothing Then 'do something, e.g.: With sr.Fill .ForeColor.SchemeColor = 13 .Visible = msoTrue .Solid End With End If End Sub '==================== --- Regards, Norman "Edward Ulle" wrote in message ... My macro creates new shapes on the worksheet. I want to group them but if no shapes were created the macro fails. How do I test for valid selection. I have tied: If Not Selection Is Nothing Then Selection.ShapeRange.Group If Not Selection.ShapeRange Is Nothing Then Selection.... But nothing works. It says "Object doesn't support this property or method" Thanks *** Sent via Developersdex http://www.developersdex.com *** |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Norman,
The situation is a little more complicated than that. I build up layers of grouped shapes on each worksheet. Some times there are not shapes in that layer and I thought a property check would work. Also I didn't want to use error handling as a programmer should anticipate something as simple as this and handle it. What I have decided to do is simple increment a counter when a new shape is created in that layer. If the counter is zero than don't try to group them into that layer. Thank. Ed *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How can I test if a cell is empty? | Excel Discussion (Misc queries) | |||
Test if the range is empty | Excel Discussion (Misc queries) | |||
Can't test for Empty objects in an array | Excel Programming | |||
Test if Clipboard is empty | Excel Programming | |||
Better way to test for empty Recordset | Excel Programming |