I need to save a selected zone to pdf.
I have look a lot of forums but my code not works.
Any idea ?
Thanks,
Bernard.
My bad code :
Code: Select all
' Error in this code.
option explicit
' Paramer : pdf file name to save.
Const PdfFile = "file:///C:/BdPrg/CalcPrgVb/SaveAsPdf/Result.pdf"
Dim oServiceManager
Dim oDesktop
Dim oDoc
Dim oSheet
Dim c
Dim l
Dim oCursor
Dim oRange
Set oServiceManager = CreateObject( "com.sun.star.ServiceManager" )
Dim args1( 0 )
Set args1( 0 ) = oServiceManager.Bridge_GetStruct( "com.sun.star.beans.PropertyValue" )
args1( 0 ).name = "Hidden"
args1( 0 ).value = False
Set oDesktop = oServiceManager.CreateInstance( "com.sun.star.frame.Desktop" )
Set oDoc = oDesktop.LoadComponentFromURL( "private:factory/scalc", "_blank", 0, args1 )
Set oSheet = oDoc.GetSheets.GetByIndex( 0 )
l = 0 : c = -1
c = c + 1 : oSheet.GetCellByPosition( c, l ).SetString( "Cell A1" )
c = c + 1 : oSheet.GetCellByPosition( c, l ).SetString( "Cell B1" )
l = l + 1 : c = -1
c = c + 1 : oSheet.GetCellByPosition( c, l ).SetString( "Cell A2" )
c = c + 1 : oSheet.GetCellByPosition( c, l ).SetString( "Cell B2" )
Set oCursor = oSheet.createCursor()
oCursor.gotoEndOfUsedArea( True )
Set oRange = oSheet.getCellRangeByPosition( 0, 0, oCursor.getRangeAddress.EndColumn _
, oCursor.getRangeAddress.EndRow )
oDoc.currentcontroller.select( oRange )
Dim FilterProps(0)
Set FilterProps(0) = oServiceManager.Bridge_GetStruct( "com.sun.star.beans.PropertyValue" )
FilterProps(0).Name = "Selection"
FilterProps(0).Value = oDoc.currentSelection
Dim args2(1)
Set args2(0) = oServiceManager.Bridge_GetStruct( "com.sun.star.beans.PropertyValue" )
Set args2(1) = oServiceManager.Bridge_GetStruct( "com.sun.star.beans.PropertyValue" )
args2(0).Name = "FilterName"
args2(0).Value = "calc_pdf_Export"
args2(1).Name = "FilterData"
args2(1).Value = FilterProps
oDoc.storeAsURL PdfFile, args2 'Error 800A03E9.
msgbox( "Script end" )
Set oServiceManager = Nothing