Macro print all open documents

Creating a macro - Writing a Script - Using the API

Macro print all open documents

Postby enfernal » Mon May 28, 2018 8:48 am

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

Postby enfernal » Mon May 28, 2018 7:27 pm

e.g Ms Excel

Maybe someone will have thoughts as under Calc to remake

Code: Select all   Expand viewCollapse view
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
enfernal
 
Posts: 2
Joined: Mon May 28, 2018 8:43 am

Re: Macro print all open documents

Postby JeJe » Mon May 28, 2018 9:18 pm

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
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 481
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro print all open documents

Postby Sébastien C » Mon May 28, 2018 11:44 pm

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   Expand viewCollapse view
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 5.2.7.2 under GNU-Linux ARMbian on the Rock64 and M$-W XP
User avatar
Sébastien C
 
Posts: 81
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests