[Risolto] Stampa diretta
Inviato: giovedì 22 settembre 2016, 0:55
Ciao, espongo prima a cosa serve la macro. Funziona così, dal foglio1 passo al foglio2 dove stampo la prima ed unica pagina che c'è, ritorno al foglio1 cancello i dati che ci sono nella prima riga sposto in alto tutti quelli che ci sono sotto e la macro finisce in attesa di un nuovo via. So che non è una soluzione molto elegante per stampare delle schede in sequenza ma è la più semplice che mi è venuta in mente. Ora il problema ERA che la macro, dopo essere stata avviata aspettava che io cliccassi invio per far partire la stampa.... Ho trovato in rete una soluzione che risolve questo problema che è quella qui sotto
La parte posticcia è quella che va da: dim args1(0) as new com.sun.star.beans.PropertyValue sino al next i
Il ciclo for next c' era e si ripeteva per tre volte non so perchè, io l'ho messo a uno e l'ho lasciato.... Ora mi sono detto perchè non facciamo un bel ciclino for next in modo che posso lanciare tutte le stampe che voglio? Così ho modificato il codice nella maniera qui sotto
Ma purtroppo non funziona, o meglio stampa una scheda ok ed una vuota....
A questo punto le domande, in primis quale è il codice corretto per inviare una pagina alla stampa senza bisogno di dare invio? Secondo cosa c'è che non va nella seconda macro che non fa stampare correttamente?
So che il messaggio è lungo, e vi ringrazio per essere arrivati in fondo, ma ho cercato di essere più chiaro possibile.
GRAZIE
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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Nr"
args1(0).Value = 3
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())
rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:Print", "", 0, Array())
args1(0).Name = "Nr"
args1(0).Value = 3
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())
rem ----------------------------------------------------------------------
dim argsXY1(0) as new com.sun.star.beans.PropertyValue
dim argsXY2(2) as new com.sun.star.beans.PropertyValue
argsXY1(0).Name = "Nr"
argsXY2(0).Name = "Copies"
argsXY2(0).Value = 1
argsXY2(1).Name = "Selection"
argsXY2(1).Value = true
argsXY2(2).Name = "Collate"
argsXY2(2).Value = false
for i=1 to 1
argsXY1(0).Value = i
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 3, argsXY1())
rem ----------------------------------------------------------------------
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Print", "", 0, argsXY2())
next i
rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Nr"
args3(0).Value = 1
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args3())
rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "By"
args4(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args4())
rem ----------------------------------------------------------------------
dim args5(0) as new com.sun.star.beans.PropertyValue
args5(0).Name = "By"
args5(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args5())
rem ----------------------------------------------------------------------
dim args6(0) as new com.sun.star.beans.PropertyValue
args6(0).Name = "By"
args6(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args6())
rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "By"
args7(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args7())
rem ----------------------------------------------------------------------
dim args8(0) as new com.sun.star.beans.PropertyValue
args8(0).Name = "By"
args8(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args8())
rem ----------------------------------------------------------------------
dim args9(0) as new com.sun.star.beans.PropertyValue
args9(0).Name = "By"
args9(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args9())
rem ----------------------------------------------------------------------
dim args10(0) as new com.sun.star.beans.PropertyValue
args10(0).Name = "By"
args10(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args10())
rem ----------------------------------------------------------------------
dim args11(0) as new com.sun.star.beans.PropertyValue
args11(0).Name = "By"
args11(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args11())
rem ----------------------------------------------------------------------
dim args12(0) as new com.sun.star.beans.PropertyValue
args12(0).Name = "By"
args12(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args12())
rem ----------------------------------------------------------------------
dim args13(0) as new com.sun.star.beans.PropertyValue
args13(0).Name = "By"
args13(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args13())
rem ----------------------------------------------------------------------
dim args14(0) as new com.sun.star.beans.PropertyValue
args14(0).Name = "By"
args14(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args14())
rem ----------------------------------------------------------------------
dim args15(0) as new com.sun.star.beans.PropertyValue
args15(0).Name = "By"
args15(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args15())
rem ----------------------------------------------------------------------
dim args16(0) as new com.sun.star.beans.PropertyValue
args16(0).Name = "By"
args16(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args16())
rem ----------------------------------------------------------------------
dim args17(0) as new com.sun.star.beans.PropertyValue
args17(0).Name = "By"
args17(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args17())
rem ----------------------------------------------------------------------
dim args18(0) as new com.sun.star.beans.PropertyValue
args18(0).Name = "By"
args18(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args18())
rem ----------------------------------------------------------------------
dim args19(0) as new com.sun.star.beans.PropertyValue
args19(0).Name = "By"
args19(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args19())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())
rem ----------------------------------------------------------------------
dim args21(0) as new com.sun.star.beans.PropertyValue
args21(0).Name = "Sel"
args21(0).Value = false
dispatcher.executeDispatch(document, ".uno:GoToStartOfRow", "", 0, args21())
rem ----------------------------------------------------------------------
dim args22(1) as new com.sun.star.beans.PropertyValue
args22(0).Name = "By"
args22(0).Value = 1
args22(1).Name = "Sel"
args22(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args22())
rem ----------------------------------------------------------------------
dim args23(1) as new com.sun.star.beans.PropertyValue
args23(0).Name = "By"
args23(0).Value = 1
args23(1).Name = "Sel"
args23(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args23())
rem ----------------------------------------------------------------------
dim args24(1) as new com.sun.star.beans.PropertyValue
args24(0).Name = "By"
args24(0).Value = 1
args24(1).Name = "Sel"
args24(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args24())
rem ----------------------------------------------------------------------
dim args25(0) as new com.sun.star.beans.PropertyValue
args25(0).Name = "Sel"
args25(0).Value = true
dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, args25())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())
rem ----------------------------------------------------------------------
dim args28(0) as new com.sun.star.beans.PropertyValue
args28(0).Name = "Sel"
args28(0).Value = false
dispatcher.executeDispatch(document, ".uno:GoToStart", "", 0, args28())
rem ----------------------------------------------------------------------
dim args29(1) as new com.sun.star.beans.PropertyValue
args29(0).Name = "By"
args29(0).Value = 1
args29(1).Name = "Sel"
args29(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args29())
rem ----------------------------------------------------------------------
dim args30(1) as new com.sun.star.beans.PropertyValue
args30(0).Name = "By"
args30(0).Value = 1
args30(1).Name = "Sel"
args30(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args30())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
rem ----------------------------------------------------------------------
dim args32(1) as new com.sun.star.beans.PropertyValue
args32(0).Name = "By"
args32(0).Value = 1
args32(1).Name = "Sel"
args32(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args32())
rem ----------------------------------------------------------------------
dim args33(1) as new com.sun.star.beans.PropertyValue
args33(0).Name = "By"
args33(0).Value = 1
args33(1).Name = "Sel"
args33(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args33())
end sub
Il ciclo for next c' era e si ripeteva per tre volte non so perchè, io l'ho messo a uno e l'ho lasciato.... Ora mi sono detto perchè non facciamo un bel ciclino for next in modo che posso lanciare tutte le stampe che voglio? Così ho modificato il codice nella maniera qui sotto
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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
dim argsXY1(0) as new com.sun.star.beans.PropertyValue
dim argsXY2(2) as new com.sun.star.beans.PropertyValue
dim args3(0) as new com.sun.star.beans.PropertyValue
dim args4(0) as new com.sun.star.beans.PropertyValue
dim args21(0) as new com.sun.star.beans.PropertyValue
dim args22(1) as new com.sun.star.beans.PropertyValue
dim args23(1) as new com.sun.star.beans.PropertyValue
dim args24(1) as new com.sun.star.beans.PropertyValue
dim args25(0) as new com.sun.star.beans.PropertyValue
dim args28(0) as new com.sun.star.beans.PropertyValue
dim args29(1) as new com.sun.star.beans.PropertyValue
dim args30(1) as new com.sun.star.beans.PropertyValue
dim args32(1) as new com.sun.star.beans.PropertyValue
dim args33(1) as new com.sun.star.beans.PropertyValue
for z = 1 to 10
args1(0).Name = "Nr"
args1(0).Value = 3
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())
rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:Print", "", 0, Array())
args1(0).Name = "Nr"
args1(0).Value = 3
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())
rem ----------------------------------------------------------------------
argsXY1(0).Name = "Nr"
argsXY2(0).Name = "Copies"
argsXY2(0).Value = 1
argsXY2(1).Name = "Selection"
argsXY2(1).Value = true
argsXY2(2).Name = "Collate"
argsXY2(2).Value = false
for i=1 to 1
argsXY1(0).Value = i
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 3, argsXY1())
rem ----------------------------------------------------------------------
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Print", "", 0, argsXY2())
next i
rem ----------------------------------------------------------------------
args3(0).Name = "Nr"
args3(0).Value = 1
dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args3())
rem ----------------------------------------------------------------------
args4(0).Name = "By"
args4(0).Value = 16
dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args4())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())
rem ----------------------------------------------------------------------
args21(0).Name = "Sel"
args21(0).Value = false
dispatcher.executeDispatch(document, ".uno:GoToStartOfRow", "", 0, args21())
rem ----------------------------------------------------------------------
args22(0).Name = "By"
args22(0).Value = 1
args22(1).Name = "Sel"
args22(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args22())
rem ----------------------------------------------------------------------
args23(0).Name = "By"
args23(0).Value = 1
args23(1).Name = "Sel"
args23(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args23())
rem ----------------------------------------------------------------------
args24(0).Name = "By"
args24(0).Value = 1
args24(1).Name = "Sel"
args24(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args24())
rem ----------------------------------------------------------------------
args25(0).Name = "Sel"
args25(0).Value = true
dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, args25())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())
rem ----------------------------------------------------------------------
args28(0).Name = "Sel"
args28(0).Value = false
dispatcher.executeDispatch(document, ".uno:GoToStart", "", 0, args28())
rem ----------------------------------------------------------------------
args29(0).Name = "By"
args29(0).Value = 1
args29(1).Name = "Sel"
args29(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args29())
rem ----------------------------------------------------------------------
args30(0).Name = "By"
args30(0).Value = 1
args30(1).Name = "Sel"
args30(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args30())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
rem ----------------------------------------------------------------------
args32(0).Name = "By"
args32(0).Value = 1
args32(1).Name = "Sel"
args32(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args32())
rem ----------------------------------------------------------------------
args33(0).Name = "By"
args33(0).Value = 1
args33(1).Name = "Sel"
args33(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args33())
next z
end sub
A questo punto le domande, in primis quale è il codice corretto per inviare una pagina alla stampa senza bisogno di dare invio? Secondo cosa c'è che non va nella seconda macro che non fa stampare correttamente?
So che il messaggio è lungo, e vi ringrazio per essere arrivati in fondo, ma ho cercato di essere più chiaro possibile.
GRAZIE