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 am assuming you want to break apart the dimensions so you can group the shapes and dimensions on the layer to easily rescale it for your documents.
That's what I explained in my original post. The macro works perfectly as I have except that it finishing in a different grouped state as expected. It has round selection glyphs instead of the usual squares
try modified code
Sub BreakDimensions()Optimization = TrueActiveDocument.BeginCommandGroup "BreakDimension"Dim sr As ShapeRange, s As ShapeSet sr = ActiveSelectionRangeFor Each s In srIf Not s.Type = cdrLinearDimensionShape Thens.RemoveFromSelectionEnd IfNext sActiveSelection.BreakApartsr.AddToSelection
Rem sr.GroupActiveSelection.Group
Optimization = FalseActiveDocument.EndCommandGroupEnd Sub
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...