Pessoal, estou com este procedimento (peguei de diversos sites)
Sub myExportToPDF()
Dim pdfName As String
Dim ArqName as String
Dim Endereco As String
Dim oDoc, oPlan
oDoc = ThisComponent
oPlan = oDoc.Sheets.getByName( "Lancamento" )
Endereco = oPlan.getCellByPosition(17,19).String
ArqName = oPlan.getCellByPosition(17,17).String
pdfName = ArqName & ".pdf"
' change the path below as per your needs
path ="file:///" & Endereco & pdfName
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
' This part makes sure only the first page gets printed
dim argsF(1) as new com.sun.star.beans.PropertyValue
argsF(0).Name = "PageRange"
argsF(0).Value = "4"
' This part sets filename and references the properties above
dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = path
args1(1).Name = "FilterName"
args1(1).Value = "calc_pdf_Export"
args1(2).name = "FilterData"
args1(2).value = argsF()
dispatcher.executeDispatch(document, ".uno:ExportDirectToPDF", "", 0, args1())
End Sub
Porém ele dá erro na última linha conforme imagem:
Observações:
O nome do arquivo em PDF não será o nome do arquivo em Calc.
Libreoffice 6.0.6.2
Win 7 Professional