First FieldNumber ignored when sorting table

H

Henry Kwan

So I'm trying to use Word's built-in Sort method to sort the values in a
table. This is the code that I'm using:

ActiveDocument.Tables(2).Select
Selection.Sort _
ExcludeHeader:=True, _
FieldNumber:="Column 3", _
FieldNumber2:="Column 2", _
FieldNumber3:="Column 1"

The weird thing is that in some cases, this code tends to ignore the first
field (i.e., FieldNumber or "Column 3" in this case).

Sorting either does not occur, or it does so incorrectly. FieldNumber2 and
FieldNumber3 sort as expected.

If I change the code to test my theory to the following, the column sorts as
expected:

Selection.Sort _
ExcludeHeader:=True, _
FieldNumber:="Column 3", _
FieldNumber2:="Column 3"

Which somewhat proves that the first FieldNumber is ignored in my case.

The only thing that I can think of is that since I'm generating the table at
runtime and this Sort method is called very shortly after I finish inserting
my last row of data into the table, it's not picking up some value that it
needs in order to call the Sort method. In some cases, sorting works on the
first FieldNumber, in others, it does not.

I'm using Word 2003.

Any help is greatly appreciated.
 
H

Henry Kwan

The workaround is to simply run the Sort method with the same arguments on
the same table twice. While I don't like this, it seems to work.
 

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