text in textbox -> wordtable cell

I

iamjohn66

How would I write to cells in an ole object linked to a word table?
I get the following error "method 'cell' of object 'table' failed"
msgbox "WordTable.object.Application.Documents(1).Tables(1).Cell(colum
row)" works so I know it can read cells like that.

I'm using the code below.

thanks if anyone can help.


Code
-------------------

Dim colum As Integer
Dim row As Integer
Dim count As Integer
colum = 1
row = 1
count = 0

Do Until count = 1
If WordTable.object.Application.Documents(1).Tables(1).Cell(colum, row) = Not Null Then
row = row + 1

End If

If WordTable.object.Application.Documents(1).Tables(1).Cell(colum, row) = Null Then
WordTable.object.Application.Documents(1).Tables(1).Cell(colum, row) = Nametxt.Text
colum = colum + 1
WordTable.object.Application.Documents(1).Tables(1).Cell(colum, row) = Birth.Text
colum = colum + 1
WordTable.object.Application.Documents(1).Tables(1).Cell(colum, row) = Death.Text
count = 1

End If

Exit Do
Loop


Code
 
H

Helmut Weber

Hi,
not too clear what you aiming at.
E.g. there is no hint of a textbox in your code.
Therefore just 2 remarks.
1) I wouldn't dim row as integer as row is a word object.
2) The array of cells in a table is cell(row, column)
not (!) cell(column, row)
---
If you are trying to access a word table from excel,
here is an example. A reference to the word library
is required (Extras, References, Microsoft Word....)
---
Sub Test55()
Dim oWrd As Word.Application
Dim oTbl As Word.Table
Set oWrd = GetObject(, "Word.Application")
Set oTbl = oWrd.Documents(1).Tables(1)
Dim iR As Integer ' row
Dim iC As Integer ' column
Dim sC As String ' string in cell
For iR = 1 To oTbl.Rows.Count
For iC = 1 To oTbl.Columns.Count
sCX = oTbl.Cell(iR, iC).Range.Text
sCX = Left(sCX, Len(sCX) - 2)
If sCX = "" Then
MsgBox "Cell(" & iR & "," & iC & ") is empty"
Else
MsgBox "Cell(" & iR & "," & iC & ") = " & sCX
End If
Next
Next
Set oTbl = Nothing
Set oWrd = Nothing
End Sub
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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