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