Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
retrieve text from table in .doc file
I've developed code open an existing .doc file and then retrieve text from a
table in the header and text from a table in the body of the document. The ..doc file has a 2 x 3 table in the header with text in cell (1, 1). The body of the document includes a 5 x 2 table with text in cell(1, 1) and cell(2, 2). The code pulls the text from the table in the body ok. But it fails to retrieve the text in the header. My code looks like, Sub ListFileContents() Dim strSourceFolder As String, strSubFolder As String Dim strFilename As String, strPathAndFilename As String Dim WordApp As Object, WordDoc As Object Dim STR1 As String Dim EndPos1 As Long Dim strText1 As String, strText2 As String On Error Resume Next strSourceFolder = "C:\testFolder\" strSubFolder = "testSubfolder\" strFilename = "test.doc" strPathAndFilename = strSourceFolder & strSubFolder & strFilename Set WordApp = CreateObject("Word.Application") Set WordDoc = WordApp.Documents.Open(strPathAndFilename) WordApp.Visible = False STR1 = WordDoc.Sections(1).Headers(wdHeaderFooterFirstPag e).Range _ .Tables(1).Rows(1).Cells(1).Range.Text Worksheets("Sheet1").Cells(1, 1).Value = STR1 With WordDoc.Tables(1) STR1 = .Cell(1, 1).Range.Text EndPos1 = Len(STR1) - 2 Worksheets("Sheet1").Cells(2, 1).Value = Mid$(STR1, 1, EndPos1) STR1 = .Cell(2, 2).Range.Text EndPos1 = Len(STR1) - 2 Worksheets("Sheet1").Cells(3, 1).Value = Mid$(STR1, 1, EndPos1) End With WordApp.Quit Set WordDoc = Nothing Set WordApp = Nothing End Sub Can anyone tell me what's wrong with this code? Thanks much. -Kevin |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
retrieve text from table in .doc file
The problem was an unselected reference. I'd been working on the code at
home and then took it to work. The reference for home use is Word 9.0 Object Library. At work it's Word 10.0 Object Library. No problem after selecting the proper reference. Sorry for bogarting the bandwidth. -Kevin "Kevin" wrote: I've developed code open an existing .doc file and then retrieve text from a table in the header and text from a table in the body of the document. The .doc file has a 2 x 3 table in the header with text in cell (1, 1). The body of the document includes a 5 x 2 table with text in cell(1, 1) and cell(2, 2). The code pulls the text from the table in the body ok. But it fails to retrieve the text in the header. My code looks like, Sub ListFileContents() Dim strSourceFolder As String, strSubFolder As String Dim strFilename As String, strPathAndFilename As String Dim WordApp As Object, WordDoc As Object Dim STR1 As String Dim EndPos1 As Long Dim strText1 As String, strText2 As String On Error Resume Next strSourceFolder = "C:\testFolder\" strSubFolder = "testSubfolder\" strFilename = "test.doc" strPathAndFilename = strSourceFolder & strSubFolder & strFilename Set WordApp = CreateObject("Word.Application") Set WordDoc = WordApp.Documents.Open(strPathAndFilename) WordApp.Visible = False STR1 = WordDoc.Sections(1).Headers(wdHeaderFooterFirstPag e).Range _ .Tables(1).Rows(1).Cells(1).Range.Text Worksheets("Sheet1").Cells(1, 1).Value = STR1 With WordDoc.Tables(1) STR1 = .Cell(1, 1).Range.Text EndPos1 = Len(STR1) - 2 Worksheets("Sheet1").Cells(2, 1).Value = Mid$(STR1, 1, EndPos1) STR1 = .Cell(2, 2).Range.Text EndPos1 = Len(STR1) - 2 Worksheets("Sheet1").Cells(3, 1).Value = Mid$(STR1, 1, EndPos1) End With WordApp.Quit Set WordDoc = Nothing Set WordApp = Nothing End Sub Can anyone tell me what's wrong with this code? Thanks much. -Kevin |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to retrieve data from a table | Excel Worksheet Functions | |||
Using 2 cells in a table to retrieve data from another table | Excel Worksheet Functions | |||
retrieve an old file erased by saving a new file with same name | Excel Discussion (Misc queries) | |||
If I accidently replace a saved file can I retrieve the old file? | Excel Discussion (Misc queries) | |||
Anyone know how to retrieve a deleted file (file has a name, comp. | New Users to Excel |