Ask Your Question

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

asked 2013-03-04 13:26:59 +0100

sup gravatar image

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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-03-03 17:50:41.315612

2 Answers

Sort by » oldest newest most voted

answered 2013-03-04 13:36:06 +0100

sup gravatar image

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("")
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
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
edit flag offensive delete link more

answered 2014-09-11 11:14:47 +0100

Kelderek gravatar image



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

edit flag offensive delete link more

Question Tools


Asked: 2013-03-04 13:26:59 +0100

Seen: 3,191 times

Last updated: Sep 11 '14