I make a selection (top) and then run my macro and though the macro does fine it leaves the selection in this state (bottom) whereby requiring me to deselect and select again
What is my code missing?
Sub BreakDimensions()Optimization = TrueActiveDocument.BeginCommandGroup "BreakDimension" Dim sr As ShapeRange, s As Shape Set sr = ActiveSelectionRange For Each s In sr If Not s.Type = cdrLinearDimensionShape Then s.RemoveFromSelection End If Next s ActiveSelection.BreakApart sr.AddToSelection sr.Group Optimization = False ActiveDocument.EndCommandGroup End Sub
I did not understand anything from your initial post about that behavior...
Can you check if inside the group it is not at least a OLE object instead of a simple shape?
Something similar hapened to me some months ago (in X8) when tried to programatically select and copy some big shape ranges. This was happening not all the time... I solved the problem only avoiding Windows Clipboard. Duplicating the initial document instead of shapes Copy - Paste and also duplicating shapes from the initial page to the other instead of copying them...
DING! DING! DING! You win a prize! Well how about a big thank you Mek? Again.
I must confess I did not understand what you need. Even if a should...
A shorter variant, maybe more elegant, would be the next, I think:
1 2 3 4 5 6 7 8 9
Sub BreakDimensions_A() Dim sr As ShapeRange, srBis As ShapeRange Set sr = ActiveSelectionRange Set srBis = sr.Shapes.FindShapes(Type:=cdrLinearDimensionShape) sr.RemoveRange srBis Set srBis = srBis.BreakApartEx sr.AddRange srBis sr.Group End Sub
FaneDuru
modified a bit
Sub BreakDimensions_A() ActiveDocument.BeginCommandGroup "BreakDimensions_A" Dim sr As ShapeRange, srBis As ShapeRange Set sr = ActiveSelectionRange Optimization = True Set srBis = sr.Shapes.FindShapes(Type:=cdrLinearDimensionShape) sr.RemoveRange srBis Set srBis = srBis.BreakApartEx sr.AddRange srBis ActiveSelection.Group Optimization = False ActiveDocument.EndCommandGroupEnd Sub
ActiveSelection.Group line - is not necessary, any more if you use sr.Group...
sr shapes range already contains all selected shapes and the group itself will be selected.
Doesn't it behave the same in your installation?
In order to use what you want to be a selection you simple can keep it in a shape (shGroup).
Set shGroup = sh.Group
If you really need to be selected, simple use: shGroup.CreateSelection...
This type of solution allows you to do whatever you want (even on a different shape not included in selection which can remain selected after, let's say, you also break it apart), because it does not involve any more the necessity to have selected shapes. Only your initial selection is necessary to identify the target to work on...