Adressing cells in table with splitted cells

B

Bogdan Zamfir

Hi,


I have a Word DOC, with a table as below.






A
B

C
D



I need to fill in the cells A, B, C and D in a VBA macro

How can I address them?

I get the reference to the table with

Set oWrdTbl = ActiveDocument.table(1)


And I can address any cell in a table with the same number of rows and colums using Cells collection of Table object

oWrdTbl.cells(1,1).Range.Text = "My text"

However I don't know how to address cells in a table as below


Can anyone help?



Thank you

Bogdan
 
W

Word Heretic

G'day "Bogdan Zamfir" <[email protected]>,

tables(1).range.cells



Bogdan Zamfir said:
Hi,


I have a Word DOC, with a table as below.






A
B

C
D



I need to fill in the cells A, B, C and D in a VBA macro

How can I address them?

I get the reference to the table with

Set oWrdTbl = ActiveDocument.table(1)


And I can address any cell in a table with the same number of rows and colums using Cells collection of Table object

oWrdTbl.cells(1,1).Range.Text = "My text"

However I don't know how to address cells in a table as below


Can anyone help?



Thank you

Bogdan

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.
 
B

Bogdan Zamfir

Hi,

My post was in html with the table drown in the message
However it seems you coudn't read HTML posts.
That's my fault, I should post a link to html page with my table format
The table was as below (you need a fixed font to see it)

+----------+-----------+
| | |
+----------+-----------+
| | A | B |
|----------+-----+-----|
| | C | D |
+----------+-----------+

The table was originally 2 x 2. and cell(2,2) was splitted to 2x2 again, and
exach new cell I named A, B, C and D

However I found a way to handle this (maybe not the most elegant, but it
worked)

The table has a regular structure
It is 8 x 7 cells, first row and first and last column are not spolited.
Also, starting from cell 1,1 to diagonal (so original 2,2, 3,3, etc) are not
splited also
All other cells are splitted to 2 x 2

What I did was to make a small sub who scan through all cells and fill it
with RowIndex and ColIndex

So the code was as below

set oCel = otable.cell(1,1)
do while true
oCell.range.Text = "R" & oCel.RowIndex & "C" & oCel.ColIndex
on error resume next
set oCel = oCel.Next
nErr = Err.Number
on error goto MyErrHand
if nErr<> 0 then
exit loop
endif
loop

Than I saved the document.
Looking through it, able to find a formula to address the cell I need based
on original row and column number (from table with unsplitted cells)

Hope this will help someone else

Regards,
Bogdan
 
W

Word Heretic

G'day "Bogdan Zamfir" <[email protected]>,

NextCell iterates through the same collection I pointed you at
initially :)


Bogdan Zamfir said:
Hi,

My post was in html with the table drown in the message
However it seems you coudn't read HTML posts.
That's my fault, I should post a link to html page with my table format
The table was as below (you need a fixed font to see it)

+----------+-----------+
| | |
+----------+-----------+
| | A | B |
|----------+-----+-----|
| | C | D |
+----------+-----------+

The table was originally 2 x 2. and cell(2,2) was splitted to 2x2 again, and
exach new cell I named A, B, C and D

However I found a way to handle this (maybe not the most elegant, but it
worked)

The table has a regular structure
It is 8 x 7 cells, first row and first and last column are not spolited.
Also, starting from cell 1,1 to diagonal (so original 2,2, 3,3, etc) are not
splited also
All other cells are splitted to 2 x 2

What I did was to make a small sub who scan through all cells and fill it
with RowIndex and ColIndex

So the code was as below

set oCel = otable.cell(1,1)
do while true
oCell.range.Text = "R" & oCel.RowIndex & "C" & oCel.ColIndex
on error resume next
set oCel = oCel.Next
nErr = Err.Number
on error goto MyErrHand
if nErr<> 0 then
exit loop
endif
loop

Than I saved the document.
Looking through it, able to find a formula to address the cell I need based
on original row and column number (from table with unsplitted cells)

Hope this will help someone else

Regards,
Bogdan

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.
 

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