Ciao a tutti,

dopo giorni di ricerche su internet che non hanno portato a nulla e nessuna risposta alla mail precedente, ho deciso di fare un workaround al problema.

La soluzione che tento di attuare è la seguente.

Quando, la macro che rileva un nuovo titolo, crea il nuovo foglio e carica dati e tabella,
aggiunge nella prima cella della colonna successiva alla tabella la funzione

ORSheet.getCellByPosition(ORCol + 1, 0).Formula = "=FSORTRATINGS(""ORRATINGS"")"

La funzione

Public Function FSORTRATINGS(wRange as Variant)
    SortRatings()
    FSORTRATINGS = "Sorted"
End Function

chiama la subroutine di Sort (presa da internet e modificata)

Sub SortRatings()
  Dim oSheet        ' Calc sheet containing data to sort.
  Dim oCellRange    ' Data range to sort.

  REM An array of sort fields determines the columns that are
  REM sorted. This is an array with two elements, 0 and 1.
  REM To sort on only one column, use:
  REM Dim oSortFields(0) As New com.sun.star.util.SortField
  Dim oSortFields(1) As New com.sun.star.util.SortField

  REM The sort descriptor is an array of properties.
  REM The primary property contains the sort fields.
  Dim oSortDesc(0) As New com.sun.star.beans.PropertyValue

  REM Get the sheet named "Sheet1"
  oSheet = ThisComponent.Sheets.getByName("Orders")

  REM Get the cell range to sort
  oCellRange = oSheet.getCellRangeByName("ORRATINGS")

  REM Select the range to sort.
  REM The only purpose would be to emphasize the sorted data.
  'ThisComponent.getCurrentController.select(oCellRange)

  REM The columns are numbered starting with 0, so
  REM column A is 0, column B is 1, etc.
  REM Sort column B (column 1) descending.
  oSortFields(0).Field = 1
  oSortFields(0).SortAscending = True

  REM If column B has two cells with the same value,
  REM then use column A ascending to decide the order.
  oSortFields(1).Field = 0
  oSortFields(1).SortAscending = True

  REM Setup the sort descriptor.
  oSortDesc(0).Name = "SortFields"
  oSortDesc(0).Value = oSortFields()

  REM Sort the range.
  oCellRange.Sort(oSortDesc())
End Sub

Credevo, con questa soluzione, di aver fatto una furbata, invece non funziona, nel senso che la routine non si innesca.

Ho provato a mettere dei MSGBOX per verificare, ma non arriva mai a lanciare la sub.

Sareste così gentili da dirmi cosa sbaglio ?
Grazie

---
Questa e-mail è priva di virus e malware perché è attiva la protezione avast! 
Antivirus.
http://www.avast.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Rispondere a