Calc - Macro to print cell range

Hi,

I have a button in a calc sheet which saves a cell range on another sheet into a PDF. It works perfectly. I’d like to extend the code to both save a PDF and print the range. Everything until “rem—print test” is working as it should.

With the code below “rem—print test” I was able to print the current sheet as a whole, but not the cell range. I’ve tried various things such as replacing “Document” with “oCellRange” in the last line of the code, replacing Array() with aFilterData or setting Document=oSheet.getCellRangeByName("$A$1:$G$41").

How do I have to modify the code to print $A$1:$G$41 only?

Thank you!

 sub DruckSPE1KM()

 oDoc   = ThisComponent
 oController = oDoc.getCurrentController()
 oSheet = oDoc.Sheets.getByName("SPE")
 oCellRange = oSheet.getCellRangeByName("$A$1:$G$41")

 dim aFilterData(0) as new com.sun.star.beans.PropertyValue
 aFilterData(0).Name = "Selection"
 aFilterData(0).Value = oCellRange
 
rem -----------------------For Filename-----------------------------------
  dim args2(2) as new com.sun.star.beans.PropertyValue
  Dim Cell        As Object
  Dim Sheet    As Object
  Dim Workmap    As Object
 
  Workmap=ThisComponent
  Sheet=Workmap.Sheets.getByName("IG-Liste")
  Cell=Sheet.getCellByposition(1,0) 'B1
rem------------------------------------------------------------------------

 dim aMediaDescriptor(1) as new com.sun.star.beans.PropertyValue
 aMediaDescriptor(0).Name = "FilterName"
 aMediaDescriptor(0).Value = "calc_pdf_Export"
 aMediaDescriptor(1).Name = "FilterData"
 aMediaDescriptor(1).Value = aFilterData()

 oDoc.storeToURL("file:///D:/Fälle/"& Cell.getString()&"/"& Cell.getString()&" SPE/"& Cell.getString()&" SPE 1 KM.pdf", aMediaDescriptor())

rem---print test
 Dim Dispatcher As Object
 Document = ThisComponent.CurrentController.Frame
 Dispatcher = createUNOService("com.sun.star.frame.DispatchHelper")
 Dispatcher.executeDispatch(Document,".uno:PrintDefault", "", 0, Array())

end sub