Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default check whether shape is a group

Hi all

I'm trying to run the following macro to reset the entries in option buttons
and check boxes.

Sub ResetSelection()

For Each shp In ActiveSheet.Shapes
For Each grp In shp.GroupItems
If TypeOf grp.DrawingObject.Object Is MSforms.OptionButton Or TypeOf
grp.DrawingObject.Object Is MSforms.CheckBox Then
grp.DrawingObject.Object.Value = False
End If
Next grp
Next shp
End Sub

This works fine for the shapes that are grouped objects, however
shp.groupitems gives an error if shp is not a group. What is the correct
syntax to perform a check on shp, e.g. something like: if shp.type =
groupedobject then...

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default check whether shape is a group

Claude,

Handle the error:

Sub ResetSelectionV2()
For Each shp In ActiveSheet.Shapes
On Error GoTo NotGrouped
For Each grp In shp.GroupItems
If TypeOf grp.DrawingObject.Object Is MSforms.OptionButton Or _
TypeOf grp.DrawingObject.Object Is MSforms.CheckBox Then
grp.DrawingObject.Object.Value = False
End If
Next grp
NotGrouped:
Resume noErr:
noErr:
Next shp
End Sub


HTH,
Bernie
MS Excel MVP


"Claude" wrote in message
...
Hi all

I'm trying to run the following macro to reset the entries in option buttons
and check boxes.

Sub ResetSelection()

For Each shp In ActiveSheet.Shapes
For Each grp In shp.GroupItems
If TypeOf grp.DrawingObject.Object Is MSforms.OptionButton Or TypeOf
grp.DrawingObject.Object Is MSforms.CheckBox Then
grp.DrawingObject.Object.Value = False
End If
Next grp
Next shp
End Sub

This works fine for the shapes that are grouped objects, however
shp.groupitems gives an error if shp is not a group. What is the correct
syntax to perform a check on shp, e.g. something like: if shp.type =
groupedobject then...

Thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default check whether shape is a group

When processing 'GroupObjects' it may be worth doing in recursive fashion as
groups can contain a tree like structure of sub groups, eg

Sub test()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
Resetter shp
Next
End Sub

Sub Resetter(shp As Shape)
Dim gi As Shape

If shp.Type = msoGroup Then
For Each gi In shp.GroupItems
Resetter gi
Next
ElseIf shp.Type = msoOLEControlObject Then
With shp.DrawingObject
If TypeOf .Object Is msforms.OptionButton Or _
TypeOf .Object Is msforms.CheckBox Then
.Object.Value = False
End If
End With
End If

End Sub

Regards,
Peter T


"Claude" wrote in message
...
Hi all

I'm trying to run the following macro to reset the entries in option

buttons
and check boxes.

Sub ResetSelection()

For Each shp In ActiveSheet.Shapes
For Each grp In shp.GroupItems
If TypeOf grp.DrawingObject.Object Is MSforms.OptionButton Or

TypeOf
grp.DrawingObject.Object Is MSforms.CheckBox Then
grp.DrawingObject.Object.Value = False
End If
Next grp
Next shp
End Sub

This works fine for the shapes that are grouped objects, however
shp.groupitems gives an error if shp is not a group. What is the correct
syntax to perform a check on shp, e.g. something like: if shp.type =
groupedobject then...

Thanks in advance



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default check whether shape is a group

This approach worked for me:

Sub ResetSelection()
Dim grps As Object, shp As Shape
For Each shp In ActiveSheet.Shapes
On Error Resume Next
Set grps = shp.GroupItems
On Error GoTo 0
If grps Is Nothing Then
Debug.Print shp.Name
Else
For Each grp In grps
Debug.Print grp.Name
Next grp
End If
Next shp
End Sub

--
Regards,
Tom Ogilvy

"Claude" wrote:

Hi all

I'm trying to run the following macro to reset the entries in option buttons
and check boxes.

Sub ResetSelection()

For Each shp In ActiveSheet.Shapes
For Each grp In shp.GroupItems
If TypeOf grp.DrawingObject.Object Is MSforms.OptionButton Or TypeOf
grp.DrawingObject.Object Is MSforms.CheckBox Then
grp.DrawingObject.Object.Value = False
End If
Next grp
Next shp
End Sub

This works fine for the shapes that are grouped objects, however
shp.groupitems gives an error if shp is not a group. What is the correct
syntax to perform a check on shp, e.g. something like: if shp.type =
groupedobject then...

Thanks in advance

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default check whether shape is a group

Hi Claude,

For grouped shapes .Type = 6. (or msoGroup)
Refer to "Type Property" in the VBA Help files then look for "Shape,
ShapeRange"

Also, selecting a shape then typing...

?Selection.ShapeRange.Type

in the Immediate Window of the VBA Editor, then pressing Enter, will
return the Shape's Type value.

Ken Johnson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default check whether shape is a group

However, it appears that you cannot access the Value property of a shape
group member. Can anyone do that?
--
Jim Cone
San Francisco, USA

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default check whether shape is a group

Hi Jim,

From the OP's code sample it would appear he has worksheet controls and
their value properties can be changed while grouped. But as you say Forms
control Value properties cannot be written while grouped, though they can be
read.

Regards,
Peter T

"Jim Cone" wrote in message
...
However, it appears that you cannot access the Value property of a shape
group member. Can anyone do that?
--
Jim Cone
San Francisco, USA



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default check whether shape is a group

Thank you to all who contributed. I solved the problem using Bernie's reply
as a basis, but very much appreciate the other information as well.

Sub ResetSelectionV3()
For Each shp In ActiveSheet.Shapes
On Error GoTo NotGrouped
For Each grp In shp.GroupItems
If TypeOf grp.DrawingObject.Object Is MSforms.OptionButton Or _
TypeOf grp.DrawingObject.Object Is MSforms.CheckBox Then
grp.DrawingObject.Object.Value = False
End If
Next grp
NotGrouped:
Resume noErr:
noErr:
On Error Resume Next
If TypeOf shp.DrawingObject.Object Is MSforms.OptionButton Or _
TypeOf shp.DrawingObject.Object Is MSforms.CheckBox Then
shp.DrawingObject.Object.Value = False
End If
Next shp
End Sub




"Claude" schrieb:

Hi all

I'm trying to run the following macro to reset the entries in option buttons
and check boxes.

Sub ResetSelection()

For Each shp In ActiveSheet.Shapes
For Each grp In shp.GroupItems
If TypeOf grp.DrawingObject.Object Is MSforms.OptionButton Or TypeOf
grp.DrawingObject.Object Is MSforms.CheckBox Then
grp.DrawingObject.Object.Value = False
End If
Next grp
Next shp
End Sub

This works fine for the shapes that are grouped objects, however
shp.groupitems gives an error if shp is not a group. What is the correct
syntax to perform a check on shp, e.g. something like: if shp.type =
groupedobject then...

Thanks in advance

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
ShemeColor Shape/Group Zurn[_59_] Excel Programming 1 July 24th 06 10:31 AM
Change order in a multi-shape group? Jay Excel Programming 0 April 5th 06 11:43 PM
text in shape group pshen Excel Programming 2 June 8th 05 07:34 PM
Get the name of a group given the reference to a shape within the group Andrew[_16_] Excel Programming 5 January 1st 04 01:08 AM
Reference oleobject within shape group Andrew[_16_] Excel Programming 4 December 24th 03 02:31 AM


All times are GMT +1. The time now is 10:31 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"