Retrieving text from specific cell in several documents

G

GaryRCassidy

I have been trying to work out how to retrieve the text from a
specific cell in all files in one folder. I'm almost there but am
missing some simple thing I'm sure. Here's where I have gotten to so
far with one of the documents open. Ultimately, the goal is to create
a separate document containing the text from the other 12.

All pointers will be appreciated.

Public Sub GetText()
MyName = Dir$("c:\test\" & "*.*")

Do While MyName <> ""
strCellText = ActiveDocument.Tables(1).Cell(1, 1).Range.Text
strCellText = Left(strCellText, Len(strCellText) - 2)
MsgBox strCellText
MyName = Dir
Loop

End Sub
 
J

Jeremy's Dad

Awesome, I've gotten a little further with the help of some code at
http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

Now that I know I can retrieve the text into a MsgBox, I need to get
the text into a new document... Here's the effort to date

====================
Public Sub GetText()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long

PathToUse = "C:\Test\"

'Set the directory and type of file to batch process

myFile = Dir$(PathToUse & "*.doc")

While myFile <> ""

'Open document
Set myDoc = Documents.Open(PathToUse & myFile)

strCellText = ActiveDocument.Tables(1).Cell(1, 1).Range.Text
strCellText = Left(strCellText, Len(strCellText) - 2)
MsgBox strCellText

'Next file in folder

myFile = Dir$()

Wend
End Sub
 
D

Doug Robbins - Word MVP

Public Sub GetText()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document, Target as Document
Dim CellText as Range

Set Target = Documents.Add
PathToUse = "C:\Test\"

'Set the directory and type of file to batch process

myFile = Dir$(PathToUse & "*.doc")

While myFile <> ""

'Open document
Set myDoc = Documents.Open(PathToUse & myFile)

Set CellText = myDoc.Tables(1).Cell(1, 1).Range
CellText.End = CellText.End - 1
Target.Range.InsertAfter CellText.FormattedText & vbCr
myDoc.Close wdDoNotSaveChanges

'Next file in folder

myFile = Dir$()

Wend
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jeremy's Dad

On Aug 16, 11:27 pm, "Doug Robbins - Word MVP"

That's wonderful Doug. Thanks for the response.

Gary
 
J

Jeremy's Dad

Taking my idea further, I have been looking at a couple of potential
uses for this routine.

One of the documents I will be looking to complete summaries from is
about 10 pages long and the table structures have been changed on
several occassions. Some cells have been merged, some tables split
etc.

Does Word 2000 VBA offer a way to identify the cell in this convoluted
document? That is to say, perhaps placing the cursor in a given cell
and running a routine that will give me the table number, row & column
number?

OHH!!! I'll go look at RowIndex and ColumnIndex....

Thanks

Gary
 
R

Russ

Gary,
Also type in the word 'information' into the Word VBA Help search window and
look at the 'information property'.
 
J

Jeremy's Dad

Russ,
Also type in the word 'information' into the Word VBA Help search window and
look at the 'information property'.

Son of a gun!!! wdStartOfRangeColumnNumber & wdEndOfRangeRowNumber
are exactly what I needed.

Thanks Russ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top