Group: microsoft.public.word.vba.general
From: "Doug Robbins - Word MVP"
Date: Monday, March 24, 2008 2:54 PM
Subject: Re: pulling select table rows based on content, pasting to new word doc (or Excel)

See the article "Find & ReplaceAll on a batch of documents in the same
folder" at:

http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

Modify the code in that article to make use of

Dim atable As Table
Dim arow As Row
Dim arange As Range

For Each atable In myDoc.Tables
For Each arow In atable.Rows
If arow.Cells.Count = 4 Then
Set arange = arow.Cells(2).Range
arange.End = arange.End - 1
If arange.Text = "V" Then
arow.Range.Copy 'the row will now be on the clipboard
End If
End If
Next arow
Next atable



--
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

"Ker_01" wrote in message
news:enOUwKejIHA.1188@TK2MSFTNGP04.phx.gbl...
> I've done a bit of VBA in Excel, but have less experience with the Word
> object model.
>
> I was just asked to help a colleague with an 'urgent' project involving
> opening every .doc file in a target directory, checking each row in each
> table to identify rows that have four columns, then for any of those that
> have "V" in the second column, copy the row plus the document name into a
> new file (either Word or Excel should work).
>
> Can anyone point me to code snippets for cycling through cells within a
> row, table rows, and entire tables?
>
> I assume the endcode will be a syntax appropriate versions of the
> following, but if I have similar code it will be faster to adapt it than
> try to do it all from scratch while learning the object model.
>
> Many thanks,
> Keith
>
> for each Document in MyDirectoryTree
> Document.open
>
> Set tempdocument = ActiveDocument
> For each Table in Document
> For each Row in Table
> If Row.cells.count = 4 then
> if Rows.cell(2) = "V" then
>
> a= ActiveDocument.name
> b=ActiveDocument.Table(?).Row(?).Cell(1)
> c=ActiveDocument.Table(?).Row(?).Cell(2)
> d=ActiveDocument.Table(?).Row(?).Cell(3)
> e=ActiveDocument.Table(?).Row(?).Cell(4)
>
> OutputDocument.Activate
> OutputDocument.Table1.addrow
> OutputDocument.Table1.cell(1) = a
> OutputDocument.Table1.cell(1) = b
> OutputDocument.Table1.cell(1) = c
> OutputDocument.Table1.cell(1) = d
> OutputDocument.Table1.cell(1) = e
>
> TempDocument.activate
> endif
> endif
> endif
> endif
>
> Document.close
> Next
>


Safety Articles | Usenet Groups | Usenet News | Bluegrass