MS word tables in vb.net

Signo.X

Well-known member
Joined
Aug 21, 2006
Messages
76
Location
Australia
Programming Experience
1-3
Hello all,

im using the follwoing to read data from a table in MS word using vb.net,
I only want to read the value at cell 2 of each row in the table.

Dim myTable As Table
Dim myRow As Row
Dim myCell As Cell
Dim cellText As String


For Each myRow In myTable.Rows
For Each myCell In myRow.Cells

cellText = myRow.Cells(2).Range.Text

cellText = Trim$(Left$(cellText, Len(cellText) - 2))

Console.WriteLine(cellText)
Next
Next

when i print the values , its printing the value of each cell twice ?@@!#

any idea why is it printing each value twice???

Thanks in advance

~ Signo.x
 
Hi

I'm not totally familiar with the syntax for reading tables in Word but looking at your code, it suggests to me that if your table has two cells then your for statement will iterate twice and therefore print the value of cellText twice. Could you not change this to one for loop to iterate through the rows and read the value of cell 2 within that row?


HTH
 
thanks for the reply ..

'Could you not change this to one for loop to iterate through the rows and read the value of cell 2 within that row?'

how do u mean? i didnt get that ?
 
like this...

Dim myTable As Table
Dim myRow As Row
Dim myCell As Cell
Dim cellText AsString


ForEach myRow In myTable.Rows

cellText = myRow.Cells(2).Range.Text

cellText = Trim$(Left$(cellText, Len(cellText) - 2))

Console.WriteLine(cellText)

Next
 
Back
Top