Align Shapes using VBA
'Following is the code to align 2 shapes. Just paste the following code 'and call AlignShapes function to align shapes with each other -------------------------------------------------------------------------------- Option Explicit Enum enmAlignTo aln1Left = 1 aln2Right = 2 aln3Top = 3 aln4Bottom = 4 aln5VerticalCenter = 5 aln6HorizontalCenter = 6 End Enum Sub AlignShapes(shpAlignMe As Shape, shpAlignWith As Shape, enmAlign As enmAlignTo) Select Case enmAlign Case aln1Left shpAlignMe.Left = shpAlignWith.Left Case aln2Right shpAlignMe.Left = shpAlignWith.Left + (shpAlignWith.Width - shpAlignMe.Width) Case aln3Top shpAlignMe.Top = shpAlignWith.Top Case aln4Bottom shpAlignMe.Top = shpAlignWith.Top + (shpAlignWith.Height - shpAlignMe.Height) Case aln5VerticalCenter shpAlignMe.Top = shpAlignWith.Top + ((shpAlignWith.Height - shpAlignMe.Height) / 2) Case aln6HorizontalCenter shpAlignMe.Left = shpAlignWith.Left + ((shpAlignWith.Width - shpAlignMe.Width) / 2) End Select End Sub
»
- Vishesh's blog
- Login or register to post comments
- 17061 reads
Thats really cool
Very handy