grouping error

jasman

Board Regular
Joined
Oct 30, 2010
Messages
141
Hi. I have some images which I have written code to group them when a command button is clicked. but it also groups the command button with the images- anyway around this? Heres my code?

Thanks


Private Sub CommandButton2_Click()
Sheets("Sheet2").Select
ActiveSheet.Shapes.SelectAll
Selection.ShapeRange.GROUP.Select
End Sub

the error says:
the specified parameter has an invalid value
runtime error 1004
<!-- / message -->
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG14Mar21
[COLOR="Navy"]Dim[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Pic [COLOR="Navy"]As[/COLOR] Shape
[COLOR="Navy"]Dim[/COLOR] Ray()
[COLOR="Navy"]Dim[/COLOR] p [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
p = 0
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Pic [COLOR="Navy"]In[/COLOR] ActiveSheet.Shapes
    [COLOR="Navy"]If[/COLOR] Pic.Type = msoPicture [COLOR="Navy"]Then[/COLOR]
        ReDim Preserve Ray(p)
        Ray(p) = Pic.Name
        p = p + 1
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Pic
ActiveSheet.Shapes.Range(Ray).Group.Select
     MsgBox Selection.Name
'[COLOR="Green"][B]Selection.Ungroup[/B][/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
what would be the code to ungroup?
also, when I click another command button which created the images, it has some code at the beginning to clear the current images on the page- but it also clears the command button. Is there anyway to fix this command button so no chnages can be made to it?

thanks again
 
Upvote 0
Try the 2 codes below, Boith run from "CommandButtons" ,One to Ungroup a "Group", and the other to delete Pictures.
Code:
Private Sub CommandButton2_Click()
Dim Grp As Shape
For Each Grp In ActiveSheet.Shapes
    If Grp.Type = msoGroup Then
        Grp.Ungroup
    End If
Next Grp
End Sub
Code:
Private Sub CommandButton3_Click()
Dim Pic As Shape
For Each Pic In ActiveSheet.Shapes
    If Pic.Type = msoPicture Then
       Pic.Delete
    End If
Next Pic
End Sub
Mick
 
Upvote 0
The delete Pictures "Code" will not work if the pictures are still a Group. You need to ungroup them first.
Mick
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,678
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top