horizontally align table in ms word page

J

JOHNV

Hi all,
I have what I think must be an easy problem. I am creating lots of tables
in an MW Word document, using C#. All of the tables appear centered on the
document page except for one. It only has one column and the table appears
aligned with the left margin. I have tried many things, but can't get it
centered horizontally on the page. Please help, as I am losing my mind. How
can I get the table centered horizontally on the page.

Thanks much.
Johnv
 
L

Lene Fredborg

Check the table properties of one of the correctly centered tables (click in
the table and select Table > Table Properties > Table tab).

The table can be aligned center by clicking the "Center" icon in the
Alignment group.
Alternatively, the table can be centered if you set text wrapping to
"Around", click "Positioning" and select "Center" as the horizontal position.
Note the settings applied to the table.

Apply the same settings to the table that needs to be centered.

In case of Word 2007, you can open the Table Properties dialog box from the
leftmost group in the Layout tab that appears when your selection is in a
table.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
J

JOHNV

Hi Lene,

Thank you for the reply. I am sorry I was not very clear in my question.
I am programmatically creating the tables, using c# and Word Interop. I have
been able to do most everything in my code, but am having a problem with this
one thing. I need to be able to programmatically adjust the table position,
from the left edge to the middle, using c# instructions. For instance, there
is a ParagraphFormat object available, but I have not been able to get the
desired results with it.

Thank you.
Johnv
 
L

Lene Fredborg

OK. I imagined you just wanted to make that final correction manually. In
VBA, you would need to manipulate the rows of the table to center the table.
For example, the following line of code will center align the first table in
the selection:

Selection.Tables(1).Rows.Alignment = wdAlignRowCenter

Maybe this can be used as a guide in your programming.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
J

JOHNV

Yes! It works great! I was trying very hard to position the entire table
as a unit, instead of individual rows. I will need to train my mind to
"think inside the box".
I noticed when Suzanne Barnhill solved a problem on this site recently, she
received a poem in payment. Since I am not a poet, please just accept my
THANK YOU!

Johnv
 
L

Lene Fredborg

Thank you for the feedback. I am glad that I could help.

Note that it is often helpful to try recording a macro in order to find out
how Word handles an operation. The code is not always elegant but you will
very often get an idea of in which direction to go. Actually, that was what I
did in this case - I never center align tables...

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

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