maria uni ha scritto:
ma esiste la possibilità senza stravolgere il codice che al click successivo ordina in senso crescente secondo la colonna A?
grazie
Nel mio precedente messaggio ti avevo risposto, comunque esistono vari modi per ottenere questo, ti faccio alcuni esempi lavorando per comodità sulla macro registrata e anche perchè ti è più familiare.
1) Come detto prima puoi usare una variabile che prende il valore da una specifica cella, come hai fatto per VALORECELLA, ad esempio se usassi la cella I4 il codice diverrebbe così
Codice: Seleziona tutto
sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
Calcoli = ThisComponent.Sheets(0)
VALORECELLA = Calcoli.getCellByPosition(8, 2).Value + 5
col1 = Calcoli.getCellByPosition(8, 3).Value
rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
dim tCol as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$A$6:$F$" & VALORECELLA
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
rem ----------------------------------------------------------------------
dim args3(6) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ByRows"
args3(0).Value = true
args3(1).Name = "HasHeader"
args3(1).Value = false
args3(2).Name = "CaseSensitive"
args3(2).Value = false
args3(3).Name = "IncludeAttribs"
args3(3).Value = true
args3(4).Name = "UserDefIndex"
args3(4).Value = 0
args3(5).Name = "Col1"
args3(5).Value = Col1
args3(6).Name = "Ascending1"
args3(6).Value = false
dispatcher.executeDispatch(document, ".uno:DataSort", "", 0, args3())
end sub
2) Usare un inputbox dove inserire il numero di colonna 6 x F e 1 x A il codice sarebbe questo
Codice: Seleziona tutto
sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
Calcoli = ThisComponent.Sheets(0)
VALORECELLA = Calcoli.getCellByPosition(8, 2).Value + 5
col1 = Int(InputBox("Per quale colonna ordinare: ","Scelta colonna", 6))
rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
dim tCol as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$A$6:$F$" & VALORECELLA
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
rem ----------------------------------------------------------------------
dim args3(6) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ByRows"
args3(0).Value = true
args3(1).Name = "HasHeader"
args3(1).Value = false
args3(2).Name = "CaseSensitive"
args3(2).Value = false
args3(3).Name = "IncludeAttribs"
args3(3).Value = true
args3(4).Name = "UserDefIndex"
args3(4).Value = 0
args3(5).Name = "Col1"
args3(5).Value = Col1
args3(6).Name = "Ascending1"
args3(6).Value = false
dispatcher.executeDispatch(document, ".uno:DataSort", "", 0, args3())
end sub
3) Usare una varibile Globale e ad ogni pressione del pulsante si alternerebbe l'ordinamento per colonna F e al successivo click l'ordinamento per colonna A e cosi da capo.
Codice: Seleziona tutto
REM ***** BASIC *****
Global sequenza
sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
Calcoli = ThisComponent.Sheets(0)
VALORECELLA = Calcoli.getCellByPosition(8, 2).Value + 5
Sequenza = Sequenza + 1
If Sequenza = 1 Then
col1 = 6
Elseif Sequenza = 2 Then
col1 = 1
Sequenza = 0
End If
rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
dim tCol as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$A$6:$F$" & VALORECELLA
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
rem ----------------------------------------------------------------------
dim args3(6) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ByRows"
args3(0).Value = true
args3(1).Name = "HasHeader"
args3(1).Value = false
args3(2).Name = "CaseSensitive"
args3(2).Value = false
args3(3).Name = "IncludeAttribs"
args3(3).Value = true
args3(4).Name = "UserDefIndex"
args3(4).Value = 0
args3(5).Name = "Col1"
args3(5).Value = Col1
args3(6).Name = "Ascending1"
args3(6).Value = false
dispatcher.executeDispatch(document, ".uno:DataSort", "", 0, args3())
end sub
4) Intervenire direttamente sul pulsante.
Le vie sono tante e diverse dipende da te.
Saluti