OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Objects Inside ~ Centered Within (http://forum.oberonplace.com/showthread.php?t=24799)

dungbtl 27-07-2017 07:34

Objects Inside ~ Centered Within
1 Attachment(s)
There are objects inside a shape, square, circle or whatever.

How to group them and become centered within that shape?

I guess they would become grouped if they aren't and center within?

See pic below.

knowbodynow 13-03-2018 03:29

Try this (seemed to work using X6):


Sub AlignGroupToObject()

Dim sr As ShapeRange
Dim s as shape
If ActiveDocument Is Nothing Or ActiveSelection.Shapes.Count = 0 Then Exit Sub

Set sr = ActiveSelection.Shapes.all

Set s = ActiveSelection.Shapes.all.Group


s.AlignToShape cdrAlignHCenter, ActiveSelection.Shapes(1)
s.AlignToShape cdrAlignVCenter, ActiveSelection.Shapes(1)

End Sub

Note: The target object is the last to be selected.

dungbtl 18-03-2018 06:06

Thanks Nobody

It works in X4 & 2017 just fine.

Pint of Guinness to your right :drink:

knowbodynow 19-03-2018 10:40

Glad it worked, thanks for the Guinness, haven't had a real one in over 20 years!

shark 20-03-2018 04:17

slightly improved code (:

Sub CenterGroup()
Dim s As Shape, sr As ShapeRange
    Set sr = ActiveSelectionRange: If sr.Count = 0 Then Beep: Exit Sub
    Set s = sr.FirstShape: sr.Remove 1 'align to bottom shape
    sr.AlignRangeToShape cdrAlignHCenter + cdrAlignVCenter, s
End Sub

dungbtl 22-10-2018 05:43


Wooo... many months later.

Yes this code is good as well.

Need some code fixing for 2018 version

All times are GMT -5. The time now is 18:53.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com