PDA

View Full Version : [SOLVED:] How to Align a Word shape to the bottom of the page with VBA?



Mikk
08-17-2016, 04:29 AM
Hello everyone,

I tried to solve this for quite some time now but I just cant find out how nor found hints online so far.
My question is how can I position a shape aligned vertically to the bottom of the page like this via VBA:

16888

Whatever I tried in VBA will always result in absolute positions like -28cm below page.
We want the Alignment mode so that our shape will not be positioned wrong when paper size is changed by the user.

My not working code so far looks like this:


'myrange is a header
Set picShape = myrange.InlineShapes.AddPicture(FileName:=strFile, LinkToFile:=False, SaveWithDocument:=True, range:=myrange).ConvertToShape
With picShape
.LockAspectRatio = True
.Height = MillimetersToPoints(15)
.WrapFormat.Type = wdWrapFront
.ZOrder msoBringToFront
.RelativeHorizontalPosition = wdRelativeHorizontalPositionRightMarginArea
.Left = -picShape.Width + MillimetersToPoints(1)
End With
picShape.Select
Dim shpr As ShapeRange
Set shpr = Selection.ShapeRange
shpr.RelativeVerticalPosition = wdRelativeVerticalPositionPage
shpr.Align msoAlignBottoms, True
the result then looks like this:
16889

Thanks in advance!
Mikk

gmayor
08-21-2016, 06:47 AM
With Selection.ShapeRange
.WrapFormat.Type = wdWrapSquare
.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionMargin
.RelativeVerticalPosition = _
wdRelativeVerticalPositionPage
.Left = CentimetersToPoints(-3.16)
.Top = wdShapeBottom
End With
will put the selected shape in the bottom left corner of the page and it will stay there if you change the paper size. You can modify the selection to reflect your shape.

Mikk
08-22-2016, 02:20 AM
Perfect, works exactly as I wanted.

Thanks a lot!