3
votes

I have created a textbox in Word and can set various properties for it, such as position, text, text style, text horizontal alignment (left/right/center), color, and so on.

But I cannot find any settings to set the vertical alignment of text in the box to Top/Middle/Bottom. There's a button for vertical alignment on the ribbon to set that property, but I can't find it through the object inspector, through Intellisense, or through searching the net. I tried recording a macro, but the only line that showed up in the macro was the VBA line to select the textbox. Nothing else. :-(

The ribbon button is beside the "set text direction" option, but I couldn't find VBA for that setting either. I also tried the Textframe2 property, but saw nothing in there for vertical alignment.

Here's the code that sets the horizontal alignment of text. Also, I included the enum that I think I need to use. But I can't find the property to accept a value from the enum.

   tbox.TextFrame.TextRange.ParagraphFormat.Alignment = wdAlignParagraphRight

WdVerticalAlignment enumeration (Word):
Name                 Value  Description
wdAlignVerticalBottom   3   Bottom vertical alignment.
wdAlignVerticalCenter   1   Center vertical alignment.
wdAlignVerticalJustify  2   Justified vertical alignment.
wdAlignVerticalTop      0   Top vertical alignment.

Does anyone know the syntax for the property that I need to set to vertically align text inside a textbox shape? Thank you

1

1 Answers

3
votes

The property is TextFrame.VerticalAnchor that uses the enumeration MsoVerticalAnchor

For example:

ActiveDocument.Shapes(1).TextFrame.VerticalAnchor = msoAnchorMiddle

(The enumeration mentioned in the question is for page layout.)