How can I export in macro as pdf with filename taken from calc cell?

I would like to export as PDF with filename computed in CALC based on same values froma spreadsheed. I will need a macro to do it.

I struggled to find it on the web, so here you go. The filename is taken from J25 cell on the first sheet (you can search for sheets based on name) as well but it is slightly more complicated). Do not forget to change the path!

sub exportAsPDFwithFilename
Dim oDescriptor

rem define variables
dim document   as object
dim dispatcher as object

rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oSheets = ThisComponent.getSheets()
oSheet0 = oSheets.getByIndex(0)

rem name of the file
filename = oSheet0.getCellRangeByName("J25").getString()

rem Prepare for PDF export
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///path/to/where/you/want/to/export/watch/out/for//non-escaped/blanks/but/maybe/it/does/not/matter/" + filename 
args1(1).Name = "FilterName"
args1(1).Value = "calc_pdf_Export"

dispatcher.executeDispatch(document, ".uno:ExportDirectToPDF", "", 0, args1())
end sub

“file:///path/to/where/you/want/to/export/watch/out/for//non-escaped/blanks/but/maybe/it/does/not/matter/”

lol

ConvertToURL (“d:\my other documents\currently\today\not finished”)