CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2008
    Posts
    12

    Exclamation problem in reading a word document

    cannot read a word.doc with more than 50 or 60 pages....while reading a word document(110 pages) the code read up to 50 pages...and then it rises an exception "COMException..... reading an item which s not in the collection"....but if i split up the word.doc in to two or three documents, the code works fine.....need help in this....


    this the code which i have used..

    Dim MyApp As Word.Application
    Dim MyDoc As Word.Document
    Dim ans As String
    Dim anstr As String
    Dim i As Integer
    Dim k As Integer
    Dim d As Integer
    Dim j As Integer
    Dim count As Integer
    Dim check As Object
    MyApp = CreateObject("Word.Application")
    MyDoc = MyApp.Documents.Open("d:\\srd3.doc")
    Dim oFile2 As System.IO.File
    Dim oWrite As System.IO.StreamWriter
    oWrite = oFile2.CreateText("D:\sample2.txt")

    count = MyDoc.Tables.Count
    For i = 1 To count
    For k = 1 To MyDoc.Tables.Item(i).Columns.Count

    If (IsNothing(MyDoc.Tables.Item(i).Rows(1).Cells(k)) = False) Then


    If(MyDoc.Tables.Item(i).Rows(1).Cells(k).Range.Text.Contains("Data Type")) Then


    MyDoc.Tables.Item(i).Rows(1).Cells(k).Range.Text.Remove(anstr.Length - 1, 1)

    d = k
    For j = 2 To MyDoc.Tables.Item(i).Rows.Count
    oWrite.Write(MyDoc.Tables.Item(i).Rows(j).Cells(d).Range.Text)
    oWrite.Write(MyDoc.Tables.Item(i).Cell(j, 1).Range.Text)
    oWrite.WriteLine(d)
    Next j

    End If
    End If

    Next k




    Next i
    MyDoc.Close()
    oWrite.Close()

  2. #2
    Join Date
    Dec 2002
    Posts
    305

    Re: problem in reading a word document

    For i = 0 to count-1
    For k = 0 To MyDoc.Tables.Item(i).Columns.Count-1


    For j = 1 To MyDoc.Tables.Item(i).Rows.Count-1

    Make these changes and try.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured