Gerry,
This is what I see when working with the Range.Text in a word table.
First cell text (in this case "AAA") followed by Chr(13), Chr(7), the next cell text ("111") followed by Chr(13), Chr(7), followed by Chr(13), Chr(7), hence my once again. To test:
[VBA]
Public Sub GenTable(iColumns As Long, iRows As Long)
Dim mAA As String
Dim marrBB() As String
Set Tbl = WrdDoc.Tables.Add(Range:=objApp.Selection.Range, _
NumRows:=iRows, NumColumns:=iColumns)
Tbl.Range.Font.Bold = True
Tbl.Columns(1).Width = 20
Tbl.Cell(1, 1).Range.Text = "AAA"
Tbl.Cell(1, 2).Range.Text = "111"
Tbl.Cell(2, 1).Range.Text = "BBB"
Tbl.Cell(2, 2).Range.Text = "222"
Tbl.Cell(3, 1).Range.Text = "CCC"
Tbl.Cell(3, 2).Range.Text = "333"
Tbl.Cell(4, 1).Range.Text = "DDD"
Tbl.Cell(4, 2).Range.Text = "444"
mAA = Tbl.Range.Text
MsgBox Asc(Mid(mAA, 4, 1)) '<- chr 13
MsgBox Asc(Mid(mAA, 5, 1)) '<- chr 7 -
'end of first cell
MsgBox Asc(Mid(mAA, 9, 1)) '<- chr 13
MsgBox Asc(Mid(mAA, 10, 1)) '<- chr 7
'- end of second cell
MsgBox Asc(Mid(mAA, 11, 1)) '<- chr 13
MsgBox Asc(Mid(mAA, 12, 1)) '<- chr 7
'- end of row ** once again
marrBB = Split(Tbl.Range.Text, Chr(13) & Chr(7))
MsgBox UBound(marrBB) '<- = 12 not 8
Set Tbl = Nothing '<- be nice, release variable
objApp.Selection.MoveEnd Unit:=wdTable, Count:=1 '<-
'move to end of table
objApp.Selection.MoveDown Unit:=wdLine, Count:=1, _
Extend:=wdMove '<- move foward 1 line
End Sub
[/VBA]
This happens in VB6 AND VBA. So in conclusion I agree with you, it holds ALL text between the start and the stop of the Range.Text.
Mr Doubtfire,
C:\test.doc is a file I loaded for testing, if you don't have it it will not load. I agree with what xCav8r has posted, the only thing is I had a lot of problems with createobject and getobject to create an instance of Word through VB. I got a lot of ActiveX couldn't create object, etc. When I changed it to New Application I got a lot fewer phone calls . I also use doevents right after New Application so word will have time to load and get going, then it ready to recieve instructions. This is what I have deterined works for me best, does not mean it is the best or preferred, just works best for me.
1.) - Tbl.Columns(1).Width is not characters You could use the autofit which would resize the columns to fit the data.
2.)
[VBA]
Sub look()
Dim A As Table
Set A = Tables.Add(Range:=Selection.Range, NumRows:=5, _
NumColumns:=5)
A.Columns(1).Width = InchesToPoints(1.25)
With A.Borders
.InsideLineStyle = wdLineStyleNone
.OutsideLineStyle = wdLineStyleNone
End With
End Sub
[/VBA]
3.) use getobject if an error occurs use create object if there is no error close activedocument - here could be a problem you have no idea if the doc needs to be saved.
4.)
[VBA]
Private Sub Command1_Click()
StartWrd "C:\test1.doc"
AddText "How are you?"
GenTable 2, 4
AddText Chr(13)
GenTable 6, 6
AddText Chr(13)
GenTable 8, 8
AddText "Thank you!"
KillWrd "C:\test.doc"
End Sub
[/VBA]
HTH