Hello everyone! new here.
I’m trying to write a code to print a pre-configured page… i tryed Chat GPT and it gave me some codes, although, none worked, i need to find out how to print a specific selection, or cell range, directly in a defined printer, i do not want to open the print configuration screen, just wanna click and print, acording to what i want…
I need the code to work on the oldest vertion, only with the native basic language of the libreoffice… where i wanna implement it does not have access to internet, i only have the basic and the libreoffice calc…
Does anybody have any clue of how doing this? it would make a huge diference in the way my spreadsheet will work…
Thankyou!
In the cod bellow i receive a error message in the line code printArgs(0).Value.setPropertyValue(“Name”, printerName) that says : that the variable of the object is not defined…
Sub Main
’ Define a impressora pré-definida
Dim printerName As String
printerName = “Nome da Impressora” ’ Substitua pelo nome da sua impressora
' Obter o objeto Document
Dim document As Object
document = ThisComponent
' Obter o objeto Dispatcher
Dim dispatcher As Object
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
' Define as células a serem impressas
Dim args1(0) As New com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$A$1:$E$18"
' Obter o objeto DispatchProvider
Dim dispatchProvider As Object
dispatchProvider = document.CurrentController.Frame
' Executa a ação de seleção de células
dispatcher.executeDispatch(dispatchProvider, ".uno:GoToCell", "", 0, args1())
' Define as opções de impressão
Dim printArgs(0) As New com.sun.star.beans.PropertyValue
printArgs(0).Name = "PrintSettings"
printArgs(0).Value = createUnoService("com.sun.star.beans.PropertyValue")
printArgs(0).Value.setPropertyValue("Name", printerName)
' Executa a impressão
document.print(printArgs())
End Sub