DreamKid Posted May 21, 2005 Posted May 21, 2005 I'm trying out the code below: Dim waXml As New Word.Application Dim wdXml As New Word.Document Try wdXml = waXml.Documents.Open(strDocPath) Dim tblXml As Word.Table Dim rowXml As Word.Row Dim cllXml As Word.Cell Dim prXml As Word.Paragraph tblXml = wdXml.Tables.Item(1) For Each cllXml In tblXml.Range.Cells For Each prXml In cllXml.Range.Paragraphs Console.WriteLine(prXml.Range.Text.ToString) Next Next tblXml = wdXml.Tables.Item(2) For Each cllXml In tblXml.Range.Cells For Each prXml In cllXml.Range.Paragraphs Console.WriteLine(prXml.Range.Text.ToString) Next Next Catch ex As Exception MsgBox("Error: " & ex.ToString) Finally wdXml.Close() waXml.Quit() End Try But an error occurs at: tblXml = wdXml.Tables.Item(1) Which said that my request collection doesn't exist. The program manage to display the data in the console but seems to have error before it terminates.. Please advise.. Thank you. Quote
herilane Posted May 23, 2005 Posted May 23, 2005 First: 'this should be without the New keyword, because you'll be opening an existing doc: Dim wdXml As New Word.Document 'should be Dim wdXml As Word.DocumentSecond: are you sure that the document has two tables? If you're not 100% sure, check wdXml.Tables.Count before proceeding. Quote
Recommended Posts