Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Test for an empty selection

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Test for an empty selection

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Test for an empty selection

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Test for an empty selection

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Test for an empty selection

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I test if a cell is empty? Victor Delta Excel Discussion (Misc queries) 10 August 8th 07 11:22 PM
Test if the range is empty dan Excel Discussion (Misc queries) 6 December 21st 06 03:59 PM
Can't test for Empty objects in an array Peter Chatterton[_4_] Excel Programming 3 July 28th 05 07:06 AM
Test if Clipboard is empty Tod Excel Programming 1 August 17th 04 05:00 PM
Better way to test for empty Recordset Tod Excel Programming 1 April 2nd 04 05:19 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"