Macro print all open documents

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
enfernal
Posts: 2
Joined: Mon May 28, 2018 8:43 am

Macro print all open documents

Post by enfernal »

Hello, all!

I am a beginner with macroes.

The macro is necessary for me for printing of all open documents in Calc

Thank you
LibreOffice, Ubuntu 14.04
enfernal
Posts: 2
Joined: Mon May 28, 2018 8:43 am

Re: Macro print all open documents

Post by enfernal »

e.g Ms Excel

Maybe someone will have thoughts as under Calc to remake

Code: Select all

Option Explicit
Dim xlApp, pBook

Set xlApp = GetExcel()
Do Until xlApp Is Nothing
    For Each pBook In xlApp.Workbooks
       pBook.PrintOut
        pBook.Close False
    Next
    xlApp.Quit
    Set xlApp = Nothing
    WScript.Sleep 2000
    Set xlApp = GetExcel()
Loop

Private Function GetExcel()
On Error Resume Next
    Dim xls
    Err.Clear
    Set xls = GetObject(,"Excel.Application")
    If Err.Number = 0 Then
        Set GetExcel = xls
    Else
        Set GetExcel = Nothing
    End If
End Function
LibreOffice, Ubuntu 14.04
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro print all open documents

Post by JeJe »

if you download Andrew Pitonyak's AndrewMacro document there's a section called "Print a Calc range" and another one "Iterate Through All Open Documents"

http://www.pitonyak.org/AndrewMacro.pdf
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Re: Macro print all open documents

Post by Sébastien C »

Hello to all,

If I may : giving a practical example, very simple, but functionnal, can giving taste of the unknow; otherwise, it may disgust... :oops:

Printing a document can be complex. You can, for example specific a huge number of variables (names of printers, size of paper, orientation of it etc.). But if you want JUST print all open ODS documents, with the default settings, then the macro is very simple:

Code: Select all

Sub printAllSpreadsheetDocuments( )
	Dim myCollection As Object, mySpreadsheetDocument As Object

	myCollection = starDesktop.getComponents().createEnumeration()

	Do While myCollection.hasMoreElements()
	 mySpreadsheetDocument = myCollection.nextElement()

	 If mySpreadsheetDocument.supportsService("com.sun.star.sheet.SpreadsheetDocument") Then
	  mySpreadsheetDocument.print(array())
	 End If
	Loop
End Sub
I hope it can help a beginner for printing all spreadsheet document, of course, but for discover the wonderful world of macros too.
:D
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
Post Reply