Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2004

Tip: Looking for answers? Try searching our database.

text in textbox -> wordtable cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
iamjohn66 - 30 Oct 2004 23:28 GMT
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
-------------------
 

--
Message posted from http://www.ExcelForum.com
Helmut Weber - 31 Oct 2004 12:53 GMT
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/
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.