Solved

Accessing objects in a group

Posted on 2013-11-05
12
186 Views
Last Modified: 2013-11-08
Is it possible to add to or delete objects from a group of drawing objects. If yes then what is the syntax?

This does not work

For Each shp In ActiveSheet.Shapes
For Each sshp In shp.GroupItems
Select Case Left(sshp.Name, InStr(sshp.Name, " ") - 1)
Case "Oval": sshp.Delete
End Select
Next sshp
Next shp
0
Comment
Question by:Saqib Husain, Syed
  • 6
  • 5
12 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39623726
Hi,

i suppose it fails when there is no group
pls try

Sub Macro()

Dim sshpTemp As Object

For Each shp In ActiveSheet.Shapes
If shp.Type = msoGroup Then
For Each sshp In shp.GroupItems
Select Case Left(sshp.Name, InStr(sshp.Name, " ") - 1)
Case "Oval": sshp.Delete
End Select
Next sshp
End If
Next shp

End Sub

Open in new window

Regards
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39624104
No, presently I have only one group in the drawing which contains some oval shapes. The line

sshp.Delete

does not work
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39624153
Hi,

Could send an example? the code works for me.

Regards
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 39624301
Which version of Excel is it?
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39624351
2007
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39625769
Here is the file I am working on
Staff-layout.xlsx
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39632811
HI,

I am supposing that you cannot delete a shape which is in a group therefore my new code

Sub Macro()

Do
    Found = False
    For Each shp1 In ActiveSheet.Shapes
        If shp1.Type = msoGroup Then
            shp1.Ungroup
            Found = True
        End If
    Next
Loop While Found = True

For Each shp2 In ActiveSheet.Shapes
    Select Case Split(shp2.Name, " ")(0)
        Case "Oval"
            shp2.Delete
    End Select
Next shp2

ActiveSheet.Shapes.SelectAll
Selection.Group
End Sub

Open in new window

Regards
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39632815
Although this is not what I wanted to do, what happens if there are many groups?

I wonder why Rory asked for the version number. Is there any variation in a certain version?
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39632824
Hi,

In the case of many groups you would to have to to create arrays with the different elements of the groups before ungrouping to be able to regroup them

I think Rorya asked for the version because in XL 2010 it is possible to delete a shape in a group but I read a comment somewhere (with no mention of the version) that you could change the properties of a shape within a group but not deleting them.

Regards
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39633012
Can this be confirmed that it works in 2010? At the moment I do not have access to 2010.
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39633063
HI,

The code you sent in your question worked perfectly on my MS Office Plus 2010 version.

Regards
0
 
LVL 43

Author Closing Comment

by:Saqib Husain, Syed
ID: 39633088
Thanks for the info and for the effort.

Saqib
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now