• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Trouble with Shape Grouping

Mike Hoff

New Member
Hi:

I am trying to use the excellent example of simulating a switch. However, when I group the shapes and them move the switch, the entire group seems to move. I can not for the life of me figure out why the rounded rectangle moves even though I specifically reference the correct grouped item. Any help would be appreciated. Is this a bug in excel? I have at this for hours. I have boiled this down to a simple workbook so as to not confuse things with my app that I am using this switch on. This switch moves to right or left depending on where you click on the rounded rectangle. If you click on the dot the switch should move to the center. Notice how the underlying rounded rectangle moves as well.

Thanks

Mike Hoff
 

Attachments

Mike

Firstly welcome to the Chandoo.org Forums

Nice job there with the switch...

I don't understand why it is moving but it is a simple job to fix
I added a small of code
Code:
Sub ResetGroupLocation()
ActiveSheet.Shapes.Range("Group1").Top = 240
ActiveSheet.Shapes.Range("Group1").Left = 250
End Sub

and called that in the moveBtn2() sub

see attached

You can find the location of the Group by using
? ActiveSheet.Shapes.Range("Group1").Top
? ActiveSheet.Shapes.Range("Group1").Left

in the Immediate pane in VBA
 

Attachments

Hi Mike ,

You can continue to use the technique you have already worked on ; however , in my opinion , moving an object is even otherwise a slow process.

The easier way to simulate this would be to just have 2 objects , and toggle their visibility and text ; using the Application.Caller property , it is easy to identify the clicked object and take the appropriate action.

This eliminates the need to identify locations , and makes the code so simple.

Narayan
 
Mike

Firstly welcome to the Chandoo.org Forums

Nice job there with the switch...

I don't understand why it is moving but it is a simple job to fix
I added a small of code
Code:
Sub ResetGroupLocation()
ActiveSheet.Shapes.Range("Group1").Top = 240
ActiveSheet.Shapes.Range("Group1").Left = 250
End Sub

and called that in the moveBtn2() sub

see attached

You can find the location of the Group by using
? ActiveSheet.Shapes.Range("Group1").Top
? ActiveSheet.Shapes.Range("Group1").Left

in the Immediate pane in VBA

Thank you for taking the time to look at my issue. I had not thought of this solution. While it does eventually put the group back in it's place, I find it a bit distracting still to see the switch move/wiggle. Makes for less than polished look in the actual application. I just don't understand why the underlying elements of the group move when I am not referencing them anywhere in the code, other than the switch button itself.
 
Hi Mike ,

You can continue to use the technique you have already worked on ; however , in my opinion , moving an object is even otherwise a slow process.

The easier way to simulate this would be to just have 2 objects , and toggle their visibility and text ; using the Application.Caller property , it is easy to identify the clicked object and take the appropriate action.

This eliminates the need to identify locations , and makes the code so simple.

Narayan

Thank you for your kind input. I am not sure how to then simulate a switch, can you give me an example. Many thanks...
 
See Narayan's suggestion
I simply copied Group 1
renamed it Group 2
Group 2 is directly over Group 1
added code for each
 

Attachments

Yup, that makes sense and I think that is what NARAYANK991 was also getting at. I think also rather than duplicating the entire group, I will just have three switch circles, one to the left one in the center for off and one to the right, and toggle the visibility of those depending on where clicked. Geez, so simple. I did confirm the issue to be related to later versions of Microsoft office. When I create this same switch in Office 2003, the problem does not exist. It does however in 2010 and 2013.

Thanks for pointing me in the right direction.!!!
 
Back
Top