4 Replies Latest reply: Aug 18, 2010 7:23 AM by Jonas Gros RSS

    How to sort (descending) straight table with macro

      Hi,

      I need to have "default sort" for straight table. I can't use simple sort, because user must be able to sort the table if he wants. So I need functionality to automatically change sort of first column when user opens table.

      I was looking at API, but only found SortBy. Is there any function where you can specify what kind of sort you need - I need DESCENDING sort.

       

      Thanks,

      Miha

        • How to sort (descending) straight table with macro

          So far - I've come to a solution:

          Sub Sort_CH27
          set tablebox = ActiveDocument.GetSheetObject("CH27")
          tablebox.SortBy 2 ' ASC
          tablebox.SortBy 2 ' DESC
          End Sub

          But this is not OK; If user sorts the table ASC, the next time it will be sorted ASC again, not DESC.

          Thanks,
          Miha

            • AW:Re: How to sort (descending) straight table with macro
              Jonas Gros

              Hey,

              I used your code to get to my solution for the same problem. Here is my workin solution:

              sub Sort
              set a = ActiveDocument.Variables("varLastSortMenge")
              var1 = a.GetContent.String

              set quelle1 = ActiveDocument.GetSheetObject("CH45")
              sort1 = quelle1.GetProperties.TableProperties.InterFieldSortOrder
              ord1 = CStr(sort1(lbound(sort1)))

              set ziel1 = ActiveDocument.GetSheetObject("CH60")
              if var1 = ord1 then
              ziel1.SortBy ord1
              end if
              ziel1.SortBy ord1

              ActiveDocument.Variables("varLastSortMenge").SetContent ord1, true
              end sub

              Hope I could help. Variable in document musst be set before... but this is self-explanatory...

            • How to sort (descending) straight table with macro

              In a straight table you can sort any column(it is by default).

              So rather than definging a macro go to chart properties -->sort -->select 1st dimension (for which you wanna apply default sorting) Keep it at the top -->select descending(if numeric field) or Z-A(if text field).

              then save your document.

              Next time when you will open the document you will have desired sorted table.