Text Box alignment

J

Jenny Fletcher

How do I find out the horizontal alignment of a Text Box?

e.g.

Dim objShape As Word.Shape
Dim objParagraph as Word.Paragraph

For Each objShape In objParagraph.Range.ShapeRange
If objShape.Type = Office.MsoShapeType.msoTextBox Then
'here I want to know whether the TextBox is left
'or right aligned

End If
Next

I'm using the Word 9.0 Object library.

I would be grateful for any insight.

Jenny
 
P

Peter Hewett

Hi Jenny Fletcher

You can do it something like this:

Public Sub TextBoxIsLeftOrRight()

' Since it's possible to align the TextBox any number of
' ways, specifically check for the alignment options
' we're interested in
With ActiveDocument.Shapes(1)
If .Left = wdShapeLeft Then
MsgBox "The horizontal alignment is Left"
ElseIf .Left = wdShapeRight Then
MsgBox "The horizontal alignment is Right"
Else
MsgBox "The horizontal alignment is neither Left or Right"
End If
End With
End Sub

Note, that though the code determines Left/Right horizontal alignment it does not tell you
whether that aligment is Margin/Page/Column etc.



How do I find out the horizontal alignment of a Text Box?

e.g.

Dim objShape As Word.Shape
Dim objParagraph as Word.Paragraph

For Each objShape In objParagraph.Range.ShapeRange
If objShape.Type = Office.MsoShapeType.msoTextBox Then
'here I want to know whether the TextBox is left
'or right aligned

End If
Next

I'm using the Word 9.0 Object library.

I would be grateful for any insight.

Jenny

HTH + Cheers - Peter
 
J

Jenny Fletcher

Thanks - just the job!
-----Original Message-----
Hi Jenny Fletcher

You can do it something like this:

Public Sub TextBoxIsLeftOrRight()

' Since it's possible to align the TextBox any number of
' ways, specifically check for the alignment options
' we're interested in
With ActiveDocument.Shapes(1)
If .Left = wdShapeLeft Then
MsgBox "The horizontal alignment is Left"
ElseIf .Left = wdShapeRight Then
MsgBox "The horizontal alignment is Right"
Else
MsgBox "The horizontal alignment is neither Left or Right"
End If
End With
End Sub

Note, that though the code determines Left/Right
horizontal alignment it does not tell you
 
J

Jay Freedman

Note, that though the code determines Left/Right horizontal alignment
it does not tell you whether that aligment is Margin/Page/Column etc.

You can get that information by checking the shape's
..RelativeHorizontalPosition to see whether it's
wdRelativeHorizontalPositionColumn, wdRelativeHorizontalPositionMargin, or
wdRelativeHorizontalPositionPage.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top