[Solved] Update Macro to save the current print range to pdf
[Solved] Update Macro to save the current print range to pdf
Hello all. I need to update the macro called when the "Close Shift" button is pressed to save the active sheet to pdf. All sheets have a print range set. I would like to save the pdf in a specified location with the sheet name as the file name.
Can anybody help me out please? Your help is truly appreciated.
Can anybody help me out please? Your help is truly appreciated.
- Attachments
-
- Shift Reconciliation v4 - Copy.ods
- (30.56 KiB) Downloaded 56 times
Last edited by Hagar Delest on Thu Jun 08, 2023 10:59 pm, edited 1 time in total.
Reason: tagged solved.
Reason: tagged solved.
OpenOffice 3.1 on Windows Vista
Re: Update Macro to save the current print range to pdf
Google is your friend:
if youare use a virtual pdf printer software:
viewtopic.php?t=35043
If you are using the built-in PDF export function:
viewtopic.php?t=79013
viewtopic.php?t=25480
https://www.google.hu/search?q=openoffi ... nt=gws-wiz
if youare use a virtual pdf printer software:
viewtopic.php?t=35043
If you are using the built-in PDF export function:
viewtopic.php?t=79013
viewtopic.php?t=25480
https://www.google.hu/search?q=openoffi ... nt=gws-wiz
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Update Macro to save the current print range to pdf
Thank you Zizi. What do you recommend i use? Virtual pdf or export pdf?
OpenOffice 3.1 on Windows Vista
Re: Update Macro to save the current print range to pdf
It depends on your knowledge on AOO/LO API. (API: Application Programming Inteface)What do you recommend i use? Virtual pdf or export pdf?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Update Macro to save the current print range to pdf
Please update your signature in this forum._____________________________________________
OpenOffice 3.1 on Windows Vista
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Update Macro to save the current print range to pdf
Print active sheet's set up print areas. Print used area if no areas are setup.
Code: Select all
REM ***** BASIC *****
Sub Main()
shx = ThisComponent.getSheets()
bMod = ThisComponent.isModified()
iUB = shx.getCount()-1
view = ThisComponent.getCurrentController()
ash = view.getActiveSheet()
ish = ash.RangeAddress.Sheet
sURL = ThisComponent.URL &"."& replace(ash.getName()," ","%20") &".pdf"
dim aOptions(0) as new com.sun.star.beans.PropertyValue
aOptions(0).Name = "FilterName"
aOptions(0).Value = "calc_pdf_Export"
REM remove print areas of all sheets
dim a(iUB )
for i = 0 to iUB
sh = shx.getByIndex(i)
a(i) = sh.PrintAreas
sh.PrintAreas = Array()
next
REM reset active sheet's print areas and save
if uBound(a(ish))>-1 then
ash.PrintAreas = a(ish)
else
ash.PrintAreas = Array(getUsedRange(ash).getRangeAddress())
endif
ThisComponent.storeToURL( sURL, aOptions())
REM restore print areas
for i = 0 to iUB
sh = shx.getByIndex(i)
sh.PrintAreas = a(i)
next
ThisComponent.setModified(bMod)
End Sub
Function getUsedRange(oSheet)
Dim oCursor1, oCursor2, addr
oCursor1 = oSheet.createCursorByRange(oSheet)
oCursor1.gotoStart()
addr = oCursor1.getRangeAddress()
oCursor2 = oSheet.createCursorByRange(oSheet)
oCursor2.gotoEnd()
addr.EndColumn = oCursor2.RangeAddress.EndColumn
addr.EndRow = oCursor2.RangeAddress.EndRow
getUsedRange = oSheet.getCellRangeByPosition(addr.StartColumn, addr.StartRow, addr.EndColumn, addr.EndRow)
End Function
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Update Macro to save the current print range to pdf
Thank you Villeroy.
I have set a print range for every sheet.
Which part of your code do i have 2 remove since the range is already defined?
I have set a print range for every sheet.
Which part of your code do i have 2 remove since the range is already defined?
OpenOffice 3.1 on Windows Vista
Re: Update Macro to save the current print range to pdf
If it is a real question for you, then I suggest you: Do not remove anything.Which part of your code do i have 2 remove since the range is already defined?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Update Macro to save the current print range to pdf
The macro removes all set up print areas, restores the print area(s) of the active sheet as the only area(s) to be printed and exports to pdf. FInally it restores all set up print areas, so the document should be the same as before starting the macro.
If the active sheet has no print area(s) set up, the used range will be set as a temporary print area.
P.S. As always, you are the one to test this macro thoroughly with
If the active sheet has no print area(s) set up, the used range will be set as a temporary print area.
P.S. As always, you are the one to test this macro thoroughly with
of your original document(s).a copy
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Update Macro to save the current print range to pdf
Thank you all for your feedback. managed to do it with your help.
OpenOffice 3.1 on Windows Vista