Get complete content from a word table cell

G

GFassauer

Hi There,

I have a problem getting the content of table cell in word. At the moment I
grab the content of a cell with code like this:
For Each celTable In .Cells
Set rngText = celTable.Range
rngText.MoveEnd Unit:=wdParagraph, Count:=-1
myText = rngText
Next

This works fine unless I have a cell that contains text with automatic
number in it, then my code only gets the text after the number. How do I
manage to get the whole text (including number from that cell)

Any help is appreciated.
GFassauer
 
P

Pesach Shelnitz

Hi,

The following macro, which is based on your code, will correctly display the
contents of each cell in a table even if there is automatic number in the
table. Notice that in addition to the changes that were needed to display the
numbering, I changed wdParagraph to wdCharacter in the call to MoveEnd.

Sub DisplayTableCellsWithNumbering()
Dim rngText As Range

With Selection.Tables(1).Range
.ListFormat.ConvertNumbersToText
For Each celTable In .Cells
Set rngText = celTable.Range
rngText.MoveEnd Unit:=wdCharacter, Count:=-1
myText = rngText.Text
MsgBox myText
Next
End With
ActiveDocument.Undo 1
End Sub
 
P

Pesach Shelnitz

Hi,

I should have mentioned that the macro displays the contents of the cells in
one table and that you need to place the cursor inside that table before
running the macro. I should have also mentioned that the macro pops up a
message box for each cell in the table. If you have a very large table, I
suggest that you test the macro on a relatively small table and then modify
it to process the contents of each cell as required.

Pesach
 

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