Home

Excel VBA Shape Rotate makes unwanted Move and Resize to Shape Group.

%3CLINGO-SUB%20id%3D%22lingo-sub-722128%22%20slang%3D%22en-US%22%3EExcel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722128%22%20slang%3D%22en-US%22%3E%3CP%3EA%20shape%20group%20is%20getting%20resized%20after%20VBA%20rotation.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20attached%20Excel%202016%20%2F%20Office%20365%20workbook%20contains%20a%20worksheet%20with%202%20sets%20of%20shapes%3A%3C%2FP%3E%3CUL%3E%3CLI%3ETriangle%201%20and%20Circle%201%20(Ungrouped)%3C%2FLI%3E%3CLI%3ETriangle%202%20and%20Circle%202%20(Grouped)%3C%2FLI%3E%3C%2FUL%3E%3CP%3EChanging%20the%20value%20(e.g.%201%20thru%20360)%20in%20cell%20H4%20executes%20Excel's%20Worksheet_Change%20script.%3C%2FP%3E%3CP%3EThis%20script%20rotates%20the%20triangles%20inside%20the%20circles.%3C%2FP%3E%3CUL%3E%3CLI%3ETriangle%201%20rotates%20properly%3C%2FLI%3E%3CLI%3ETriangel%202%20also%20rotates%2C%20however%2C%20it%20is%20contained%20inside%20of%20a%20shape%20group%2C%20and%20the%20entire%20shape%20group%20unexpectedly%20resizes%20and%20moves.%3C%2FLI%3E%3C%2FUL%3E%3CP%3ECan%20someone%20explain%20why%20the%20shape%20group%20resizes%20and%20moves%3F%3C%2FP%3E%3CP%3ECan%20someone%20provide%20a%20solution%20that%20prevents%20the%20shape%20group%20from%20resizing%3F%3C%2FP%3E%3CP%3EI%20have%20attached%20a%20sandbox%20xlsm%20file%20so%20you%20can%20duplicate%20this%20issue%20for%20yourself.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120705i01373DCC1F2B934B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Excel-Sandbox.JPG%22%20title%3D%22Excel-Sandbox.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EBefore%20Triangle%20Rotation%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120706i4E825540F3F131ED%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Excel-Sandbox-After%20Rotation.JPG%22%20title%3D%22Excel-Sandbox-After%20Rotation.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EAfter%20Triangle%20Rotation%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-722128%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-722196%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722196%22%20slang%3D%22en-US%22%3EI'm%20unable%20to%20reproduce%20the%20issue%2C%20both%20shape%20combinations%20rotate%20the%20same%20and%20keep%20their%20sizes.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-722218%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722218%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366980%22%20target%3D%22_blank%22%3E%40Grosner%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20tried%20to%20rotate%20them%2C%20but%20they%20both%20rotate%20correctly%20as%20the%20screenshot%20below!%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120724iEACA506CD7249FF2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Rotate%20Shapes.png%22%20title%3D%22Rotate%20Shapes.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20there%20is%20a%20bug%20in%20your%20current%20version%20of%20Office%2C%20so%20please%20make%20sure%20you%20have%20the%20latest%20version%20of%20Office%20365.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-722216%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722216%22%20slang%3D%22en-US%22%3E%3CP%3EOk%2C%20Thanks%20for%20trying.%20It%20is%20interesting%20you%20cannot%20duplicate%20the%20resize%20issue.%3CBR%20%2F%3EAre%20you%20using%20Excel%202016%20%2F%20Office%20365%20with%20latest%20updates%20applied%2C%20as%20I%20am%3F%3C%2FP%3E%3CP%3EAdditionally%2C%20be%20sure%20to%20enter%20a%20different%20value%20into%20Cell%20H4%20and%20press%20enter.%3C%2FP%3E%3CP%3EYou%20may%20need%20to%20do%20this%20several%20times%20in%20order%20to%20see%20the%20effect%2C%20because%20the%20resize%20and%20move%20occur%20in%20very%20small%20increments.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-722245%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722245%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20fully%20updated.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20look%20closely%20at%20the%20result%20image%2C%20you%20will%20see%20the%20image%20on%20the%20right%20is%20slightly%20larger.%20I%20am%20guessing%20you%20only%20entered%20a%20value%20into%20cell%20H4%20one%20time.%20If%20you%20enter%20any%20value%20several%20more%20times%2C%20pressing%20enter%20after%20each%20entry%2C%20I%20think%20you%20will%20see%20the%20changes%20more%20clearly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20right%20click%20and%20select%20size%20and%20properties.%20This%20should%20show%20the%20same%20value%20for%20height%20and%20width%20for%20the%20grouped%20object.%20If%20it%20does%20not%2C%20then%20you%20have%20replicated%20my%20situation.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-722532%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722532%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366980%22%20target%3D%22_blank%22%3E%40Grosner%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOk%2C%20I%20confirm%20the%20issue!%3C%2FP%3E%3CP%3EIt%20seems%20like%20the%20grouping%20causes%20this%20weird%20bug!%3C%2FP%3E%3CP%3EYou%20can%20send%20feedback%20to%20the%20Excel%20Team%20about%20it.%3C%2FP%3E%3CP%3EFor%20now%2C%20the%20workaround%20is%20to%20forget%20the%20grouping!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-722578%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722578%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F35679%22%20target%3D%22_blank%22%3E%40Haytham%20Amairah%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20confirming%20this%20issue.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EI%20will%20provide%20feedback%20to%20Microsoft.%3C%2FP%3E%3CP%3EIt%20would%20be%20nice%20if%20anyone%20has%20an%20actual%20workaround.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-724630%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-724630%22%20slang%3D%22en-US%22%3ESome%20tips%20to%20ease%20sending%20feedback%3A%3CBR%20%2F%3E-%20Use%20Word%20(or%20Powepoint)%20to%20get%20screen-shots%20(Insert%20tab%20on%20ribbon%2C%20Screen-shot%20drop-down)%2C%20prior%20and%20after%20the%20VBA%20code%20has%20run%3CBR%20%2F%3E-%20Paste%20the%20screen-shots%20in%20your%20Excel%20window%3CBR%20%2F%3E-%20Also%20paste%20a%20screen-shot%20of%20your%20VBA%20code%20in%20the%20same%20Excel%20window%3CBR%20%2F%3E-%20Open%20File%2C%20Feedback%20and%20click%20send%20a%20frown%3CBR%20%2F%3E-%20Check%20the%20include%20screen-shot%20box%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-725269%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-725269%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366980%22%20target%3D%22_blank%22%3E%40Grosner%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20workaround%20plan%20is%20to%20use%20Excel%20VBA%20to%20prevent%20the%20unwanted%20move%20and%20resize%20of%20the%20shape%20group%20is%20to%3A%3C%2FP%3E%3CP%3E1.%20Use%20VBA%20to%20ungroup%20the%20group%20object%20(that%20way%20I%20can%20rotate%20my%20shape%20without%20affecting%20the%20size%20or%20position%20of%20the%20shape%20group%20(because%20my%20shape%20will%20no%20longer%20be%20inside%20of%20the%20group)%3C%2FP%3E%3CP%3EFor%20the%20example%20on%20how%20to%20do%20this%20see%3A%26nbsp%3B%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Fvba%2Fapi%2Fexcel.shape.ungroup%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Fvba%2Fapi%2Fexcel.shape.ungroup%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.%26nbsp%3B%20Perform%20the%20rotation%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E3.%26nbsp%3B%20Regroup%20the%20ungrouped%20shaped%20objects%20back%20into%20their%20original%20group.%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20information%20on%20regrouping%20see%3A%26nbsp%3B%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Fvba%2Fapi%2Fexcel.shaperange.regroup%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Fvba%2Fapi%2Fexcel.shaperange.regroup%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20pointers%20on%20how%20to%20code%20this%20in%20VBA%20would%20be%20appreciated%3A%3C%2FP%3E%3CP%3E1.%20First%20save%20the%20group%20name%20and%20all%20of%20its%20member%20shape%20(and%20subgroup)%20names%26nbsp%3B%3C%2FP%3E%3CP%3E2.%20Ungroup%20the%20grouped%20Object%3C%2FP%3E%3CP%3E3.%20Rotate%20one%20shape%20in%20the%20group%20by%20changing%20the%20.Rotation%20property%20value%3C%2FP%3E%3CP%3E4.%20Regroup%20the%20object%20back%20into%20it's%20original%20group%20name%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-725338%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-725338%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366980%22%20target%3D%22_blank%22%3E%40Grosner%3C%2FA%3E%20Perhaps%20this%20gives%20you%20some%20ideas%3A%3C%2FP%3E%0A%3CPRE%3ESub%20Demo()%0A%20%20%20%20Dim%20oObj%20As%20Object%0A%20%20%20%20Dim%20i%20As%20Integer%0A%20%20%20%20Dim%20oGroup%20As%20Object%0A%20%20%20%20Dim%20stMembers()%20As%20String%0A%20%20%20%20Dim%20sGroupName%20As%20String%0A%20%20%20%20%0A%20%20%20%20'Set%20your%20grouped%20object%20to%20oObj%20first.%0A%20%20%20%20'Then%3A%0A%20%20%20%20%0A%20%20%20%20sGroupName%20%3D%20oObj.Name%0A%20%20%20%20%0A%20%20%20%20Set%20oGroup%20%3D%20oObj.Ungroup%0A%20%20%20%20If%20Not%20oGroup%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20ReDim%20stMembers(1%20To%20oGroup.Count)%0A%20%20%20%20%20%20%20%20For%20i%20%3D%201%20To%20oGroup.Count%0A%20%20%20%20%20%20%20%20%20%20%20%20stMembers(i)%20%3D%20oGroup(i).Name%0A%20%20%20%20%20%20%20%20Next%0A%20%20%20%20%20%20%20%20'%20Now%20rotate%20any%20member%20of%20the%20group%20and%20then%3A%3CBR%20%2F%3E%20%20%20%20%20%20%20%20'%20regroup%0A%20%20%20%20%20%20%20%20ActiveSheet.DrawingObjects(1%2C%20stMembers()).Group.Name%20%3D%20sGroupName%0A%20%20%20%20End%20If%0A%0AEnd%20Sub%0A%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-728692%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-728692%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%3C%2FP%3E%3CP%3EWith%20a%20few%20tweaks%20(see%20attached%20workbook)%26nbsp%3B%20Jan's%20solution%20enables%20Excel%20VBA%20to%20ungroup%20and%20regroup%20shapes.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20an%20alternative%20that%20uses%20fewer%20lines%20of%20code%2C%20there%20is%20a%20way%20to%20use%20use%20the%20Shapes%20Ungroup%20and%20Shapes%20Regroup%20method%20(ineffective%20for%20shape%20groups%20that%20are%20contained%20inside%20another%20shape%20group)%3A%3C%2FP%3E%3CPRE%3E'Group%203%20Rotate%20-%20Solution%20B%3CBR%20%2F%3EDim%20ShGroup%20As%20Shape%3CBR%20%2F%3ESheet1.Shapes(%22Group%203%22).Ungroup%3CBR%20%2F%3ESheet1.Shapes.range(Array(%22Triangle%203%22)).Rotation%20%3D%20range(%22H4%22).Value%3CBR%20%2F%3ESet%20ShGroup%20%3D%20Sheet1.Shapes.range(Array(%22Triangle%203%22)).Regroup%3CBR%20%2F%3EShGroup.Name%20%3D%20%22Group%203%22%3C%2FPRE%3E%3CP%3E%26nbsp%3BI%20have%20posted%20both%20solutions%20in%20the%20attached%20workbook.%20Here%20are%20the%20illustrations%20of%20the%20worksheet%20when%20the%20zoom%20is%20and%20is%20not%20set%20to%20100%25%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-right%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F121617i4E3B76350AB3DB6D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Sandbox-1-100%25%20Zoom.JPG%22%20title%3D%22Sandbox-1-100%25%20Zoom.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EExcel%20VBA%20-%20Rotate%20while%20Zoom%20%3D%20100%25%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-right%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F121618iD056FB09C00E034A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Sandbox-1-98%25%20Zoom.JPG%22%20title%3D%22Sandbox-1-98%25%20Zoom.JPG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EExcel%20VBA%20-%20Rotate%20while%20Zoom%20%3D%2098%25%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EExcel%20Resizes%20%26amp%3B%20Moves%20Shape%20Objects%20when%20Zoom%20is%20Not%20100%25%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EAs%20the%20attached%20worksheet%20and%20images%20above%20illustrate%2C%20when%20an%20Excel%20Sheet's%20zoom%20is%20not%20100%25%2C%20Excel%20VBA%20that%20changes%20a%20shape%20%3CU%3Econtained%20in%20a%20grouped%20shape%3C%2FU%3E%20object%20will%20cause%20the%20grouped%20shape%20and%20its%20components%20to%20resize%20and%20to%20move%20if%20the%20Excel%20zoom%20is%20not%20100%25.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEssentially%2C%20the%20values%20for%20shape%20object's%20the%20.Left%2C%20.Top%2C%20.Height%2C%20and%20.Width%20change%20when%20a%20property%2C%20such%20as%20.Rotation%2C%20is%20changed.%20Why%20this%20happens%20is%20a%20mystery%20to%20me%2C%20but%20a%20Google%20search%20will%20find%20other%20instances%20of%20similar%20behaviors.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CH3%20id%3D%22toc-hId-1593121081%22%20id%3D%22toc-hId-1593121081%22%20id%3D%22toc-hId-1593121081%22%3EExcel%20VBA%20Future%20Support%3C%2FH3%3E%3CP%3EOne%20would%20have%20hoped%20that%20Microsoft%20fixed%20these%20issues%2C%20however%2C%20a%20Help-%26gt%3B%20About%20done%20while%20in%20Excel%20VBA%20shows%20version%20%3CEM%3EVisual%20Basic%20for%20Applications%207.1.%3C%2FEM%3E%20According%20to%20this%20%3CA%20title%3D%22Visual%20Basics%20for%20Applications%22%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FVisual_Basic_for_Applications%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EWikipedia%20article%20on%20Visual%20Basic%20For%20Applications%3C%2FA%3E%26nbsp%3Bthe%20Excel%20VBA%20program%20first%20appeared%20in%201993%20and%20was%20last%20updated%20in%20Office%202013%20(about%206%20-%207%20years%20ago%20as%20of%20the%20date%20of%20my%20writing)%20when%20it%20was%20updated%20to%20version%207.1%20so%20perhaps%20there%20is%20no%20longer%20any%20interest%20in%20improving%20Excel%20VBA.%20Perhaps%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fvisualstudio%2Fvsto%2Fcreate-vsto-add-ins-for-office-by-using-visual-studio%3Fview%3Dvs-2019%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EVisual%20Studio%20Tools%20for%20Office%3C%2FA%3E%26nbsp%3Bwill%20provide%20a%20better%20alternative%20for%20Excel%20VBA.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CH3%20id%3D%22toc-hId--959035880%22%20id%3D%22toc-hId--959035880%22%20id%3D%22toc-hId--959035880%22%3EA%20Few%20More%20Excel%20VBA%20Tips%20for%20Working%20with%20Shapes%3C%2FH3%3E%3CP%3EA%20few%20lines%20of%20Excel%20VBA%20Code%20that%20came%20in%20handy%20were%3A%3C%2FP%3E%3CPRE%3EApplication.ScreenUpdating%20%3D%20False%20'Disable%20Screen%20Updating%20to%20hide%20intermediate%20changes%3CBR%20%2F%3EActiveWindow.zoom%20%3D%20100%20'%20Use%20to%20reset%20zoom%20to%20100%25%20so%20shapes%20will%20not%20move%20around%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-733621%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20Shape%20Rotate%20makes%20unwanted%20Move%20and%20Resize%20to%20Shape%20Group.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-733621%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366980%22%20target%3D%22_blank%22%3E%40Grosner%3C%2FA%3E%20VBA%20future%3A%20Don't%20expect%20them%20to%20do%20any%20updates%20to%20the%20VBA%20editor.%20They%20do%20state%20that%20new%20functionality%20will%20be%20added%20to%20the%20object%20model.%20Omissions%20and%20bugs%20in%20the%20OM%20are%20likely%20to%20be%20the%20same%20for%20VBA%20and%20for%20the%20Visual%20Studio%20Office%20COM%20interface.%20If%20you%20want%20to%20be%20future-proof%2C%20start%20learning%20JavaScript%20and%20the%20new%20JS%20Office%20programming%20paradigm.%20That%20too%20has%20limitations%20though.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Grosner
Occasional Contributor

A shape group is getting resized after VBA rotation.

 

The attached Excel 2016 / Office 365 workbook contains a worksheet with 2 sets of shapes:

  • Triangle 1 and Circle 1 (Ungrouped)
  • Triangle 2 and Circle 2 (Grouped)

Changing the value (e.g. 1 thru 360) in cell H4 executes Excel's Worksheet_Change script.

This script rotates the triangles inside the circles.

  • Triangle 1 rotates properly
  • Triangel 2 also rotates, however, it is contained inside of a shape group, and the entire shape group unexpectedly resizes and moves.

Can someone explain why the shape group resizes and moves?

Can someone provide a solution that prevents the shape group from resizing?

I have attached a sandbox xlsm file so you can duplicate this issue for yourself.

Excel-Sandbox.JPGBefore Triangle RotationExcel-Sandbox-After Rotation.JPGAfter Triangle Rotation

11 Replies
I'm unable to reproduce the issue, both shape combinations rotate the same and keep their sizes.

Ok, Thanks for trying. It is interesting you cannot duplicate the resize issue.
Are you using Excel 2016 / Office 365 with latest updates applied, as I am?

Additionally, be sure to enter a different value into Cell H4 and press enter.

You may need to do this several times in order to see the effect, because the resize and move occur in very small increments. 

@Grosner

 

Hi,

 

I've tried to rotate them, but they both rotate correctly as the screenshot below!

Rotate Shapes.png

 

I think there is a bug in your current version of Office, so please make sure you have the latest version of Office 365.

 

Regards

I am fully updated. 

 

If you look closely at the result image, you will see the image on the right is slightly larger. I am guessing you only entered a value into cell H4 one time. If you enter any value several more times, pressing enter after each entry, I think you will see the changes more clearly.

 

Also, right click and select size and properties. This should show the same value for height and width for the grouped object. If it does not, then you have replicated my situation.

@Grosner

 

Ok, I confirm the issue!

It seems like the grouping causes this weird bug!

You can send feedback to the Excel Team about it.

For now, the workaround is to forget the grouping!

 

Regards

@Haytham Amairah 

Thank you for confirming this issue.  

I will provide feedback to Microsoft.

It would be nice if anyone has an actual workaround.

 

Thanks!

 

Some tips to ease sending feedback:
- Use Word (or Powepoint) to get screen-shots (Insert tab on ribbon, Screen-shot drop-down), prior and after the VBA code has run
- Paste the screen-shots in your Excel window
- Also paste a screen-shot of your VBA code in the same Excel window
- Open File, Feedback and click send a frown
- Check the include screen-shot box

@Grosner 

My workaround plan is to use Excel VBA to prevent the unwanted move and resize of the shape group is to:

1. Use VBA to ungroup the group object (that way I can rotate my shape without affecting the size or position of the shape group (because my shape will no longer be inside of the group)

For the example on how to do this see: 
https://docs.microsoft.com/en-us/office/vba/api/excel.shape.ungroup

 

2.  Perform the rotation

 

3.  Regroup the ungrouped shaped objects back into their original group. 

For information on regrouping see: 
https://docs.microsoft.com/en-us/office/vba/api/excel.shaperange.regroup

 

Any pointers on how to code this in VBA would be appreciated:

1. First save the group name and all of its member shape (and subgroup) names 

2. Ungroup the grouped Object

3. Rotate one shape in the group by changing the .Rotation property value

4. Regroup the object back into it's original group name

 

@Grosner Perhaps this gives you some ideas:

Sub Demo()
    Dim oObj As Object
    Dim i As Integer
    Dim oGroup As Object
    Dim stMembers() As String
    Dim sGroupName As String
    
    'Set your grouped object to oObj first.
    'Then:
    
    sGroupName = oObj.Name
    
    Set oGroup = oObj.Ungroup
    If Not oGroup Is Nothing Then
        ReDim stMembers(1 To oGroup.Count)
        For i = 1 To oGroup.Count
            stMembers(i) = oGroup(i).Name
        Next
        ' Now rotate any member of the group and then:
' regroup ActiveSheet.DrawingObjects(1, stMembers()).Group.Name = sGroupName End If End Sub

@Jan Karel Pieterse

With a few tweaks (see attached workbook)  Jan's solution enables Excel VBA to ungroup and regroup shapes.

 

For an alternative that uses fewer lines of code, there is a way to use use the Shapes Ungroup and Shapes Regroup method (ineffective for shape groups that are contained inside another shape group):

'Group 3 Rotate - Solution B
Dim ShGroup As Shape
Sheet1.Shapes("Group 3").Ungroup
Sheet1.Shapes.range(Array("Triangle 3")).Rotation = range("H4").Value
Set ShGroup = Sheet1.Shapes.range(Array("Triangle 3")).Regroup
ShGroup.Name = "Group 3"

 I have posted both solutions in the attached workbook. Here are the illustrations of the worksheet when the zoom is and is not set to 100%Sandbox-1-100% Zoom.JPGExcel VBA - Rotate while Zoom = 100%Sandbox-1-98% Zoom.JPGExcel VBA - Rotate while Zoom = 98%

 

 

 

Excel Resizes & Moves Shape Objects when Zoom is Not 100%:

As the attached worksheet and images above illustrate, when an Excel Sheet's zoom is not 100%, Excel VBA that changes a shape contained in a grouped shape object will cause the grouped shape and its components to resize and to move if the Excel zoom is not 100%.

 

Essentially, the values for shape object's the .Left, .Top, .Height, and .Width change when a property, such as .Rotation, is changed. Why this happens is a mystery to me, but a Google search will find other instances of similar behaviors. 

 

Excel VBA Future Support

One would have hoped that Microsoft fixed these issues, however, a Help-> About done while in Excel VBA shows version Visual Basic for Applications 7.1. According to this Wikipedia article on Visual Basic For Applications the Excel VBA program first appeared in 1993 and was last updated in Office 2013 (about 6 - 7 years ago as of the date of my writing) when it was updated to version 7.1 so perhaps there is no longer any interest in improving Excel VBA. Perhaps the Visual Studio Tools for Office will provide a better alternative for Excel VBA. 

 

A Few More Excel VBA Tips for Working with Shapes

A few lines of Excel VBA Code that came in handy were:

Application.ScreenUpdating = False 'Disable Screen Updating to hide intermediate changes
ActiveWindow.zoom = 100 ' Use to reset zoom to 100% so shapes will not move around

 

@Grosner VBA future: Don't expect them to do any updates to the VBA editor. They do state that new functionality will be added to the object model. Omissions and bugs in the OM are likely to be the same for VBA and for the Visual Studio Office COM interface. If you want to be future-proof, start learning JavaScript and the new JS Office programming paradigm. That too has limitations though.