WORD 2007 VBA VERTICALALIGN PROPERTY

J

JBusby

Is there any way to justify a block of text (vertically) in a table cell
using VBA?
 
J

Jonathan West

JBusby said:
Is there any way to justify a block of text (vertically) in a table cell
using VBA?

Yes. Set the VerticalAlignment property of the relevant Cell object.
 
J

JBusby

Thanks for responding, Jonathan.
Your response provides me with the perfect comment to describe the coding
itself. But my attempts at "the coding itself" - without much knowledge or
experience in VBA - haven't been very successful.
By recording a macro, I was able to copy the code that seemed relevant to
the task, but to no avail:

Sub VertAlignJstfy()
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.Cells.VerticalAlignment = wdCellAlignVerticalJustify
End Sub

Any suggestions?

P.S.
Does any know where I might find some "beginners info" on the VBA Object
Browser? (e.g. How best to understand and use it.)
 
J

Jean-Guy Marcil

JBusby said:
Thanks for responding, Jonathan.
Your response provides me with the perfect comment to describe the coding
itself. But my attempts at "the coding itself" - without much knowledge or
experience in VBA - haven't been very successful.
By recording a macro, I was able to copy the code that seemed relevant to
the task, but to no avail:

What does "but to no avail" mean exaclty? If you want a solution to a
specific problem, specfic details would be useful. :)

I assume you ran the code you posted on a cell.
What did the cell contain?
How is the row formatted?
What were your expectations?
What did you observe?

Meanwhile, I do not have access to a Word 2007 machine, but the following
code ran just fine:

With Selection.Cells(1)
.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
.VerticalAlignment = wdCellAlignVerticalCenter
End With

I guess you only need to change
wdCellAlignVerticalCenter
by
wdCellAlignVerticalJustify
(Verticall justification of cells is not available in 2003, so I can't test
that part... but be aware that generally, vertical justification does not
always produce the desired results..., I have used it in sections with
varying degrees of satisfaction... Also, keep in mind that empty paragraphs
are also "justified".)
 
J

JBusby

Hello, and thanks, Jean-Guy.

My expectations were:
(1) that a table cell could be vertically justified independently of another
cell - or nested table - in the same row, and
(2) that my page layout would have vertical alignment in a table cell behave
in the same way as vertical alignment in Page Setup - with the vertical
alignment of text on the last line of every page occurring exactly at the
bottom margin.

The cell contained text only. The adjoining cell in the same row contained a
nested table with an in-line graphic.

The row was formatted with
"Specify Height" checked,
"Row Height is: At Least", and with
"Allow Row to Break across Pages" checked.

The Column Dialogue Box showed "Preferred Width" checked, and I changed the
"Measure In:" setting to Percent.

The code you suggested works fine for "Top", "Center", and "Bottom"
settings for vertical alignment, but substituting "Justify" for any of these
in the code results only in the active table cell being "high-lighted."
 
J

Jean-Guy Marcil

JBusby said:
Hello, and thanks, Jean-Guy.

My expectations were:
(1) that a table cell could be vertically justified independently of another
cell - or nested table - in the same row, and
(2) that my page layout would have vertical alignment in a table cell behave
in the same way as vertical alignment in Page Setup - with the vertical
alignment of text on the last line of every page occurring exactly at the
bottom margin.

The cell contained text only. The adjoining cell in the same row contained a
nested table with an in-line graphic.

The row was formatted with
"Specify Height" checked,
"Row Height is: At Least", and with
"Allow Row to Break across Pages" checked.

The Column Dialogue Box showed "Preferred Width" checked, and I changed the
"Measure In:" setting to Percent.

The code you suggested works fine for "Top", "Center", and "Bottom"
settings for vertical alignment, but substituting "Justify" for any of these
in the code results only in the active table cell being "high-lighted."

There seems to be something particular with the vertical alignment in cells.
As I wrote, I do not have access to Word 2007 (which introduced this
propoerty), so I cannot test this.

One idea though. if you do it manually, does it work?
If not, then it is not the code, there is something going on in Word itself.
 

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