Looking for a UI suggestion for sorting tables

J

John... Visio MVP

I have a document that has a toolbar that will generate a series of tables
at the end of the document and the user is allowed to resort the tables
based on their preferance.

Two of the tables contain page numbers and these tables have been changed
from two column to one column so that the page number can have a dot leader.
So now, it is a bit tricker to sort these tables by page number. So now the
table has to be sorted by field within column.

So I have a routine to sort these tables and I could add a button to the
toolbar that determines which table they are in and give the user the
appropriate sort choices, but I was wondering if there was a way to tie the
sort directly to the table.

John... Visio MVP
 
K

Klaus Linke

John... Visio MVP said:
I have a document that has a toolbar that will generate a series of tables
at the end of the document and the user is allowed to resort the tables
based on their preferance.

Two of the tables contain page numbers and these tables have been changed
from two column to one column so that the page number can have a dot
leader. So now, it is a bit tricker to sort these tables by page number.
So now the table has to be sorted by field within column.

So I have a routine to sort these tables and I could add a button to the
toolbar that determines which table they are in and give the user the
appropriate sort choices, but I was wondering if there was a way to tie
the sort directly to the table.

John... Visio MVP


Hi John,

How about writing your sorting macro so it looks at the table and determines
the right way to sort it?

That might turn out to be as simple as checking the number of columns:

For each myTable in ActiveDocument.Tables
If myTable.Columns.Count=1 then
' sort stuff with tab leader
Else
' regular table sorting
Endif
Next myTable

Regards,
Klaus
 
J

John... Visio MVP

Klaus Linke said:
Hi John,

How about writing your sorting macro so it looks at the table and
determines the right way to sort it?

That might turn out to be as simple as checking the number of columns:

For each myTable in ActiveDocument.Tables
If myTable.Columns.Count=1 then
' sort stuff with tab leader
Else
' regular table sorting
Endif
Next myTable

Regards,
Klaus


Thanks Klaus

The tables are labeled with bookmarks so it is easy to determine how to
sort. The question was more about UI suggestions on how to invoke the macro.

Though you do bring up an interesting point. The special sort only applies
to tables with a tab leader. Of course, I still need a way for the user to
indicate that they want to sort the table.

John...
 
J

Jay Freedman

Thanks Klaus

The tables are labeled with bookmarks so it is easy to determine how to
sort. The question was more about UI suggestions on how to invoke the macro.

Though you do bring up an interesting point. The special sort only applies
to tables with a tab leader. Of course, I still need a way for the user to
indicate that they want to sort the table.

John...

If you follow Klaus's suggestion, then the UI problem is solved simply by naming
the macro TableSort. That will intercept the Sort command on the Table menu
(and, in Word 2007, the Sort button on the Home ribbon).
 
J

John... Visio MVP

Jay Freedman said:
If you follow Klaus's suggestion, then the UI problem is solved simply by
naming
the macro TableSort. That will intercept the Sort command on the Table
menu
(and, in Word 2007, the Sort button on the Home ribbon).


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup
so all may benefit.


Interesting idea. I had considered that earlier, but after a little
thinking, identifying the special tables is relatively easy. The tables are
a single column and the cell, includeing the title, contains a tab. So if I
check that it is a single column table with a tab in the first cell, I can
then use the content if that cell (the title) to prompt the user for sort
order.

One thing, I can intercept the sort routine, but how do I bail out and go to
the real sort routine if it is not a special table?

John... Visio MVP
 
J

Jay Freedman

Interesting idea. I had considered that earlier, but after a little
thinking, identifying the special tables is relatively easy. The tables are
a single column and the cell, includeing the title, contains a tab. So if I
check that it is a single column table with a tab in the first cell, I can
then use the content if that cell (the title) to prompt the user for sort
order.

One thing, I can intercept the sort routine, but how do I bail out and go to
the real sort routine if it is not a special table?

John... Visio MVP

Sub TableSort()
Dim oTbl As Table
If Selection.Information(wdWithInTable) Then
Set oTbl = Selection.Tables(1)
' If oTbl is special table then
' do special sort
' Else
Dialogs(wdDialogTableSort).Show
' End If
Else
' ordinary sort of non-table text
Dialogs(wdDialogTableSort).Show
End If
End Sub

It would be possible to bypass the dialog and just call either oTbl.Sort or
Selection.Sort, but I think you really want to allow the user to set the
parameters as usual.
 
J

John... Visio MVP

Thanks Jay.

John... Visio MVP
Jay Freedman said:
Sub TableSort()
Dim oTbl As Table
If Selection.Information(wdWithInTable) Then
Set oTbl = Selection.Tables(1)
' If oTbl is special table then
' do special sort
' Else
Dialogs(wdDialogTableSort).Show
' End If
Else
' ordinary sort of non-table text
Dialogs(wdDialogTableSort).Show
End If
End Sub

It would be possible to bypass the dialog and just call either oTbl.Sort
or
Selection.Sort, but I think you really want to allow the user to set the
parameters as usual.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup
so all may benefit.
 

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