Macro to ID multiple sequential tables by keyword and resequence

B

BillS

I have a Word document which is generated exporting data from another
application. I am trying to find a way to easily identify the tables which
have a particular common word word in the 1st row of each of those tables,
and then be able to change the order in which the tables appear in Word. If
the way to do this uses some sort of listing of the tables and uniques data
from a few cells in each of the tables, that would be helpful. I don't know
if this can be done using some sort of move up/move down feature as I have
seen in other programs.

Any help would be greatly appreciated.

Thanks
 
G

Graham Mayor

Does the document contain only tables? If not what else does it constrain
and what is its relationship to the tables.
What is the particular word?
If the particular word appears in all the tables, how will the new table
order be established?
It is easy enough to establish whether the word exists in a particular cell
eg for row 1 column 2 and the word 'test'

Dim oTable As Table
Dim oRng As Range
Dim sWord As String
sWord = "test"
For i = 1 To ActiveDocument.Tables.Count
Set oTable = ActiveDocument.Tables(i)
If InStr(1, oTable.Cell(1, 2).Range, sWord) Then
MsgBox "The word is found in Table " & i
End If
Next i

It's what you do with it when found that is unclear. An obvious thing to do
would be to write the table range to a new document, but in what order?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

BillS

Graham, thanks for responding.

The document contains quite a few tables but also includes paragraphs of
text outside of the tables. The group of tables I want to identify will all
be one after another with one blank line between them. The 1st table I want
to identify will never be the 1st table in the document, but the ones I want
to identify to rearrange are all one after another with only a blank line
between them. Basically I want a way to move the identified tables up and
down but they would never need to be rearranged outside of the area where the
1st to last identified consecutive tables exist.

I am using Word 2002 with XP SP3.

This is what I envision but it may be asking too much:

Suppose I have three consecutive tables in the middle oa document, ach of
which has only the word "Grey" in the 1st row of each table (the 1st row is a
table width cell). Is there a way to develop a macro which can then produce
a list (not to be visible in the document after using) which would display
the contents of two different cells from the 2nd row in each of those cells
with the word "Grey" in the 1st line, and then using the list, move the
change the order of those tables in the Word doc? (something like dragging
the list items up and down which also move the table referred to up and down)

Thanks for your help.
 
G

Graham Mayor

If the macro is to identify the tables that need to be moved, then that
table must be uniquely identifiable. From your description it is not. It is
merely a table somewhere in the middle of the document with at least one
table before it. Then there are other tables which may contain the word
'Grey' in the first row, which need to be re-ordered, but re-ordered how and
with what relation to the other tables and/or the rest of the document.
Macros can only do what you tell them to do and they do so literally. At
present the concept is so vague as to defy a solution.

What you ask *may* be possible but not from the supplied information. It is
also possible to extract and store the content of identifiable cells in a
table, but what do you want to do with that information if it is 'not to be
visible after using'?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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