How to get center of selection in VBA?

Welcome. Is there any way to get coordinates of origin selection point ?

I have written a simple macro that copies the width to the selected objects from another object, and I am looking for a way to keep the origins points of the objects in place.

that is the code:

Sub CopyWidth()

    ActiveDocument.Unit = cdrMillimeter
    Dim s As Shape, sBeMySize As Shape
    Dim sr As ShapeRange
  
    
    If ActiveSelectionRange.Count < 2 Then
          MsgBox "Nothing Selected !"
         Exit Sub
       Else
        
          
          Set sr = ActiveSelectionRange.ReverseRange
          Set sBeMySize = sr.LastShape
          sBeMySize.GetSize w, h
    
    sr.Remove sr.IndexOf(sBeMySize)
    
    ActiveDocument.BeginCommandGroup "group"
    For Each s In sr.Shapes
        s.SetSize w, y
    Next s
    
    End If
    ActiveDocument.EndCommandGroup
End Sub

Parents
  • I've written some macros that do exactly that sort of thing - record the position of a shape, transform it in some way, and then restore the position.

    In X5 and newer, I know that one can use the properties Shape.CenterX and Shape.CenterY.

    I don't know if the Center properties are available in X4. If not, then you could figure out the center position from the position (e.g., Shape.LeftX, Shape.BottomY) and the size (Shape.SizeWidth, Shape.SizeHeight). Again, I don't have X4 to check, but I think those properties are available there. Go back far enough in time, and one had to use .PositionX and .PositionY.

    You can also look at SetSizeEx, which allows an "anchor point" to be specified for resizing the shape.

Reply Children
No Data