Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How do you retrieve the sort order from a table?

Hello:
I'm using the following script to retrieve the columns and sort order from an object, but how do I retrieve whether the column is being sorted ASC or DESC?
Thanks.
Richard
--------------------------------
set chart = ActiveDocument.GetSheetObject("CH01")
cols = chart.GetProperties.TableProperties.InterFieldSortOrder
output = ""

for i = lbound(cols) to ubound(cols)
output = output + "sort priority " & i+1 & " for column " & cols(i)+1 & ",  " & i
next

msgbox output
2 Replies
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Check with this.

set dimension = chart.GetProperties.Dimensions

msgbox dimension(0).SortCriteria.SortByAscii

If it shows 1 then sort done by asc. -1 means Desc.0 means sort is not done by Text(ABC).

For numeric use SortByNumeric instead of SortByAscii.

Celambarasan

Not applicable
Author

Celambarasan:

While this retrieves the default sort order, it doesn't retrieve the current sorted order.  For example, using the code at the bottom of this message, values for 8 columns are retrieved with column 3 selected for sorting, as:

3, 1, 2, 4, 5, 6, 7, 8

What I would like to be returned is:

3 desc, 1 asc, 2 asc, 4 asc, 5 asc, 6 asc, 7 asc, 8 asc

The default sort order for all columns is asc, which is what .SortCriteria.SortByAscii returns.  However, if the user elects to sort it a different way through the interface (right click on column, select Sort) it overrides the default sort order.  It's that value I'm looking for.

Are there any extensions off of the array -- something like cols(i).GetSortDirection?

Also, thanks for your help.

Richard

set chart = ActiveDocument.GetSheetObject("CH117")
cols = chart.GetProperties.TableProperties.InterFieldSortOrder

for i = lbound(cols) to ubound(cols)
if i < ubound(cols) Then
output = output & cols(i)+1 & ", "
Else
output = output & cols(i)+1
End if
next

msgbox output