Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

WORD 2007 VBA VERTICALALIGN PROPERTY

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JBusby - 05 Mar 2008 06:02 GMT
Is there any way to justify a block of text (vertically) in a table cell
using VBA?
Signature

JBusby

Jonathan West - 06 Mar 2008 14:39 GMT
> 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.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

JBusby - 07 Mar 2008 05:02 GMT
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.)

Signature

JBusby

> > 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.
Jean-Guy Marcil - 07 Mar 2008 15:11 GMT
> 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".)
JBusby - 08 Mar 2008 05:01 GMT
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."

Signature

JBusby

> > Thanks for responding, Jonathan.
> > Your response provides me with the perfect comment to describe the coding
[quoted text clipped - 29 lines]
> varying degrees of satisfaction... Also, keep in mind that empty paragraphs
> are also "justified".)
Jean-Guy Marcil - 10 Mar 2008 19:53 GMT
> Hello, and thanks, Jean-Guy.
>
[quoted text clipped - 20 lines]
> 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.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.