Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Extract all non-table data from Word

Hello,

I am attempting to extract text data from a Microsoft Word document into
Excel. Each separate linebreak and sentence is parsed into a separate cell.

The problem is that there are several portion of the document that have
tables, which have text that I don't want to include.

Is there any way to detect text that is embedded within a table?

The code I'm using is as follows:

Sub Get_Text()


Dim rbreakpt As Long
Dim lbreakpt As Long
Dim roffset As Long
Dim curr_Row As Long


Dim SRS_Sent As String
Dim SRS_Temp As String
Dim SRS_Print As String

Set ActiveWB = ActiveWorkbook
Set objWord = CreateObject("Word.Application")
objWord.Documents.Open "C:\Work\Stuff.doc", False, True

Rem Access the document
Set currentDocument = objWord.Documents(1)

curr_Row = 1
lbreakpt = 1

SRS_Sent =
currentDocument.TablesOfContents.Application.Activ eDocument.Content.Text
SRS_Temp = SRS_Sent

While ((InStr(lbreakpt, SRS_Sent, vbLf, vbTextCompare)) Or _
(InStr(lbreakpt, SRS_Sent, vbCr, vbTextCompare)))

rbreakpt = InStr(lbreakpt, SRS_Sent, Chr(13), vbTextCompare)
roffset = rbreakpt - lbreakpt
SRS_Temp = Mid(SRS_Sent, lbreakpt, roffset)
lbreakpt = rbreakpt + 1

While (InStr(1, SRS_Temp, ".", vbTextCompare) And Len(SRS_Temp) 2)
SRS_Print = Trim(Left(SRS_Temp, InStr(1, SRS_Temp, ".", _
vbTextCompare)))

ActiveWB.Worksheets(1).Cells(curr_Row, 1).Value = Trim(SRS_Print)
SRS_Temp = Right(SRS_Temp, Len(SRS_Temp) - _
InStr(1, SRS_Temp, ".", vbTextCompare))

'DOC filename
ActiveWB.Worksheets(1).Cells(curr_Row, 2).Value = currentDocument

curr_Row = curr_Row + 1
Wend


'Output rows of any data greater than 1 char
If (Len(SRS_Temp) 1) Then
curr_Row = curr_Row + 1

'DOC req text
ActiveWB.Worksheets(1).Cells(curr_Row, 1).Value = SRS_Temp

'DOC filename
ActiveWB.Worksheets(1).Cells(curr_Row, 2).Value = currentDocument
End If

Wend

'Close the current document
currentDocument.Close

Set currentDocument = Nothing

End Sub



Thanks in advance.
Reply
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
Macro to Extract Text From Word Table Into Excel? V. Hatherley Excel Discussion (Misc queries) 1 August 27th 06 04:12 PM
Extract MS Excel Data embedded in MS Word qualityprocess Excel Discussion (Misc queries) 0 April 20th 06 05:52 PM
How to extract data from Word Form into Excel arunjoshi[_19_] Excel Programming 1 March 27th 06 04:05 PM
Extract data (not in table) from Word to Excel hellokitty77 Excel Discussion (Misc queries) 1 January 14th 06 01:51 PM
Extract MS word data to MS Excel GTS[_2_] Excel Programming 3 July 27th 04 02:44 PM


All times are GMT +1. The time now is 12:13 AM.

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

About Us

"It's about Microsoft Excel"