read line from table cell for vba in ms word

Hi,

I need to read a line in ms word table cell. There are 3 line in a cell and I'd like to read line by line and put a line in a string variable. Would anyone be willing to help me here I'm so desperate with the answer since I tried everything and none are working.

What I did so far:
If (Mid(theTable.Cell(caseStartRow, 2).Range.Text, 1, _
Len(theTable.Cell(caseStartRow, 2).Range.Text) - 2)) = chrs$(13) Then

objFile.WriteLine ("")
objFile.WriteLine ("")
End If

Please help. Thanks so much!!


Answer this question

read line from table cell for vba in ms word

  • Deep123

    Hi Navajo,

    You are genius, you know! It works perfectly. Thank you so much!

    Would you mind helping me for this problem:
    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=675347&SiteID=1

    I know you know how to solve it, it's just a simple problem.

    Thank you before!


  • Jerry Frame

    Have a look at the Split function. This seems to do what you want:

    lineArray = Split(theTable.Cell(caseStartRow, 2).Range.Text, Chr$(13))


  • redneon

    Here's an example of code that will do this:

    Option Explicit

    Public Sub main()
    Dim strCellText As String
    Dim strCellTextLines As New Collection
    Dim vv As Variant

    strCellText = ThisDocument.Tables(1).Cell(1, 1).Range.Text
    Set strCellTextLines = ParseLines(strCellText)
    MsgBox "Lines of text found = " & CStr(strCellTextLines.Count)

    For Each vv In strCellTextLines
    MsgBox vv
    Next vv

    Set strCellTextLines = Nothing
    End Sub

    Private Function ParseLines(tStr As String) As Collection
    Dim tColl As New Collection, tptr As Integer, tlastptr As Integer, tCurrStr As String
    tlastptr = 1

    With tColl
    Do
    tptr = InStr(tlastptr, tStr, Chr(13))
    If tptr = 0 Then Exit Do

    tCurrStr = Mid(tStr, tlastptr, tptr - tlastptr)
    tColl.Add tCurrStr

    tlastptr = tptr + 1
    Loop
    End With

    Set ParseLines = tColl
    End Function

    Feel free to email if you've got questions.



  • read line from table cell for vba in ms word