Table issues

P

papamobil68

Hi
I have 2 issues with a table with I dont understand:
1) This 2 commands format all column of my table to "centered", not only the
first one. Why is that?
WordTable.Columns.Item(1).Select;
WordApp.Selection.Range.ParagraphFormat.Alignment(1);

2) This 4 commands does only format cell(1,1) to "centered", not the whole
column.
WordTable.Columns.Item(1).Select;
WordApp.Selection.Range.ParagraphFormat.Alignment(1);
WordTable.Columns.Item(2).Select;
WordApp.Selection.Range.ParagraphFormat.Alignment(2);

Btw: Code may look a bit strange because it runs in an ERP-Module (Excel as
Automation Object).


Thank you for your help.
 
S

Stephanie Krieger

Hi,

Just get rid of the 'Item(#)' entry in each line --

You can write WordTable.Columns(1).Select ... etc.
instead.

That should work -- let me know if it doesn't.

Best,
Stephanie Krieger
author of Microsoft Office Document Designer
email: MODD_2003 at msn dot com
blog: arouet.net
 
H

Helmut Weber

Hi,
as there is no column.range, due to the fact, that Word
organizes tables in a linear way, you have to address each cell
seperately, unless they contain text. In that case, I have
posted a solution, which could be modified.
http://www.google.de/groups?hl=de&l...:Helmut+author:Weber&hl=de&lr=&sa=G&scoring=d
I don't know yet, how to access cells that way, which contain nothing,
except the end-of-cell mark.
Anyway:
Sub Test445()
Dim oCll As Cell
With ActiveDocument.Tables(1).Columns(2)
.Select
For Each oCll In Selection.Cells
oCll.Range.Paragraphs.Alignment = wdAlignParagraphCenter
Next
End With
End Sub
---
As far as selection vs. range is concerned,
the advantage of range over selection is questionable,
when it comes to tables.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
S

Stephanie Krieger

Hi, Helmut,

You don't have to iterate through each cell. It's the
Columns collection object you want to use. The code I
posted prior to your post will work. Give it a test with
this example... just place your insertion point anywhere
in the table you want to format (because I'm using the
selection object, rather than the active document object):

Sub testformat()

Selection.Tables(1).Columns(1).Select
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter

End Sub

Best,
Stephanie
 
P

papamobil68

Hi

Thanx for your valuable help.
I now works, I used the columns collection as on the beginning, but the 2nd
line without the range object.

WordTable.Columns.Item(1).Select;
WordApp.Selection.ParagraphFormat.Alignment(1);
'WordApp.Selection.Range.ParagraphFormat.Alignment(1);

As I use word in automation from MS Navision, I think not all is working the
same way, for example .item(x) must be used, .columns(x) does not work.
Unfortunately I also dont have "for each" and the like.

Anyway, is the use of selection the only way to accomplish that task? On the
beginning I was very sure there must be something like
"WordTable.Columns.Item(1).Alignment(1)?
 
H

Helmut Weber

Hi Stephanie,
right you are.
There are always ways of improvement,
and there is always an opportunity to learn.
Thank you.
Helmut Weber
 
S

Stephanie Krieger

Hi,

I'm afraid I'm not familiar with Navision. But you don't
have to use the Selection object -- I just used that for
example. Tables can work with either the selection object
or the ActiveDocument object. If you use the
ActiveDocument object, you have to indicate the tables
order in the document -- but you don't have to click into
the table to affect it. For example, here's the line to
select the first column of the fifth table in the
document:

ActiveDocument.Tables(5).Columns(1).Select

Honestly, I'm not sure if that answers the question you
asked. As mentioned, I don't know Navision, but if I can
still help at all, feel free to send me an e-mail. I
think this is my last chance to visit newsgroups this
week.

Best,
Stephanie
email: MODD _ 2003 at msn dot com
 

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