LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default 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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to retrieve data from a table GRK Excel Worksheet Functions 1 June 17th 09 11:16 PM
Using 2 cells in a table to retrieve data from another table Andy G Excel Worksheet Functions 0 March 19th 08 11:12 PM
retrieve an old file erased by saving a new file with same name Nagesh Adoni Excel Discussion (Misc queries) 1 March 28th 07 02:45 PM
If I accidently replace a saved file can I retrieve the old file? kamabiv Excel Discussion (Misc queries) 1 May 11th 05 10:26 PM
Anyone know how to retrieve a deleted file (file has a name, comp. Patinak New Users to Excel 2 April 3rd 05 08:53 PM


All times are GMT +1. The time now is 10:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"