Macro to print documents in the same directory

Creating a macro - Writing a Script - Using the API

Macro to print documents in the same directory

Postby OOKapitan » Mon Aug 14, 2017 2:34 pm

Hello.
        I'm currently working in OpenOffice Calc, and I often have to print more than 40 files at once. Select all, PCM, printing does not work for me. Tell me, please, can there be a macro that allows you to print all the files in the same folder in which the file is located, where does this macro run from? I used to work in Excel, but at work only OpenOffice is installed, so now I'm working on it. If I know more or less excel macros, then I do not understand anything in OO macros. Help me please.
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby JohnSUN-Pensioner » Mon Aug 14, 2017 2:59 pm

Not the answer, just a little explanation: when OOKapitan writes "PCM", he meant the right click of the mouse
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.4, LibreOffice 5.4.2.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
User avatar
JohnSUN-Pensioner
Volunteer
 
Posts: 761
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Macro to print documents in the same directory

Postby OOKapitan » Mon Aug 14, 2017 3:02 pm

JohnSUN-Pensioner wrote:Not the answer, just a little explanation: when OOKapitan writes "PCM", he meant the right click of the mouse

So it is not a mystake.
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby Zizi64 » Mon Aug 14, 2017 3:10 pm

If I know more or less excel macros, then I do not understand anything in OO macros.


This task requires a quite complex macro.
I suggest you: Hire somebody to write this macro for you.

There is a section of this Forum, named: Paid support.

https://forum.openoffice.org/en/forum/v ... m.php?f=53
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.4; AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7965
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Postby OOKapitan » Mon Aug 14, 2017 3:14 pm

Ho is able easilly to write such mscro, please, write me this macros to me.
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby RoryOF » Mon Aug 14, 2017 3:18 pm

I think this can be done quite easily with a macro at the Operating System level. OpenOfice can take command line arguments, one of which is to print a file or files passed as arguments.
https://wiki.openoffice.org/wiki/Framework/Article/Command_Line_Arguments

It should be simple to write a Windows batch file to read a directory, t hen feed each file name into the OO command line until there are no more files left.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28918
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Postby RoryOF » Mon Aug 14, 2017 3:38 pm

Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28918
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Postby OOKapitan » Mon Aug 14, 2017 3:43 pm

RoryOF wrote:It should be simple to write a Windows batch file to read a directory, t hen feed each file name into the OO command line until there are no more files left.

Do, please
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby RoryOF » Mon Aug 14, 2017 4:00 pm

With respect, you want it, you write it. I don't need to print files in such a way. I've already done some research for you and the process now should now be achievable using your existing skills gained from writing Excel macros,
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28918
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Postby OOKapitan » Mon Aug 14, 2017 4:05 pm

Who can write me the example of the macro?
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby Villeroy » Mon Aug 14, 2017 5:30 pm

Shell command to send all ODF documents in D:\Data\PrintDocs\ to the default printer:
Code: Select all   Expand viewCollapse view
soffice.exe -p D:\Data\PrintDocs\*.od?

Same with explicit printer name:
Code: Select all   Expand viewCollapse view
soffice.exe -pt PrinterName D:\Data\PrintDocs\*.od?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26709
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to print documents in the same directory

Postby OOKapitan » Tue Aug 15, 2017 9:21 am

Villeroy wrote:Shell command to send all ODF documents in D:\Data\PrintDocs\ to the default printer:
Code: Select all   Expand viewCollapse view
soffice.exe -p D:\Data\PrintDocs\*.od?

Same with explicit printer name:
Code: Select all   Expand viewCollapse view
soffice.exe -pt PrinterName D:\Data\PrintDocs\*.od?

all in the derrictory the file with macro is?
PrinterName in
Code: Select all   Expand viewCollapse view
soffice.exe -pt PrinterName D:\Data\PrintDocs\*.od?
I need t change to the name of my printer?
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby robleyd » Tue Aug 15, 2017 9:56 am

You run this from a command prompt - it is not an OpenOffice macro.

Code: Select all   Expand viewCollapse view
soffice.exe -pt PrinterName D:\Data\PrintDocs\*.od?


Change PrinterName to your printer name only if you do not want to use the default printer.

Change D:\Data\PrintDocs\ to the directory where you keep the files you want to print. If you only want to print Calc spreadsheets, change *od? to *.ods then all the spreadsheets in the directory you have named will be printed.
Cheers
David
Apache OpenOffice Developer Build 4.2.0 9820 - Slackware 14.2 - 64 bit
LibreOffice 6.0.7.3 - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 2716
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Macro to print documents in the same directory

Postby OOKapitan » Tue Aug 15, 2017 10:25 am

I understand and will test it. However what about an OpenOffice macro? I am just afraid to crash something on PC at work.
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby RoryOF » Tue Aug 15, 2017 10:40 am

You are more likely to crash something using a macro.
Make a small test directory with two or three trivial files and try using that.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28918
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Postby OOKapitan » Tue Aug 15, 2017 10:47 am

RoryOF wrote:You are more likely to crash something using a macro.
Make a small test directory with two or three trivial files and try using that.

Thank you very much.
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby OOKapitan » Tue Aug 15, 2017 10:49 am

robleyd wrote:You run this from a command prompt

May i create a bat file? Will it work? Or only from a command promt?
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby robleyd » Tue Aug 15, 2017 10:54 am

Use a .bat file, command prompt or even a shortcut icon.
Cheers
David
Apache OpenOffice Developer Build 4.2.0 9820 - Slackware 14.2 - 64 bit
LibreOffice 6.0.7.3 - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 2716
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Macro to print documents in the same directory

Postby RoryOF » Tue Aug 15, 2017 10:55 am

Start by using a command prompt and a small trial directory; when you have it working then is time to write a .bat file.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28918
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Postby OOKapitan » Tue Aug 15, 2017 4:56 pm

Nevertheless, is anyone able to write the macro?
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby Zizi64 » Tue Aug 15, 2017 7:28 pm

Tibor Kovacs, Hungary; LO4.4.7, LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.4; AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7965
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Postby OOKapitan » Wed Aug 16, 2017 10:07 am

Is anyone able to give me an I read a bit the links a post before, however I do something wrong when triing to adaptate the codes to my need.
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby Zizi64 » Wed Aug 16, 2017 10:43 am

Please upload your .ODF type file with the embedded macro code that you wrote.
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.4; AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7965
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Postby OOKapitan » Wed Aug 16, 2017 11:04 am

Here's what I got.
      But:
    1) it prints out from the directory c:\printpath, but I would like the macro to let me select a folder or to print out from the same folder the macro is in (to select the folder would be better);
    2) after each document asks whether it is printed or not, but I would like the macro after selecting a folder just to print all files in it.
      Also it would be better if the macro could print only files with the extension xls.
Help me please.
Attachments
Печать из заданной папки.odt
(20.31 KiB) Downloaded 58 times
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby Zizi64 » Wed Aug 16, 2017 12:10 pm

1) it prints out from the directory c:\printpath, but I would like the macro to let me select a folder or to print out from the same folder the macro is in (to select the folder would be better);


The code snippet on the linked page contains: how you can select a specific directory:

Code: Select all   Expand viewCollapse view
...
Dim sPath
  sPath = getFolder("Please select a folder") & GetPathSeparator()
...



Function getFolder(sTitle AS String, optional sInitDir) AS String
   oPicker = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker")
   oPicker.setTitle(sTitle)
   if not ismissing(sInitDir) then oPicker.setDisplayDirectory(sInitDir)
   if oPicker.execute() then getFolder = oPicker.getDirectory()
End Function
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.4; AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7965
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Postby OOKapitan » Wed Aug 23, 2017 4:42 pm

I tried. The macro allowes me to select the folder, but prints nothing. I forgot to say that the files must be opened visibly or they won't be printed.
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby Zizi64 » Wed Aug 23, 2017 7:08 pm

I tried. The macro allowes me to select the folder, but prints nothing. I forgot to say that the files must be opened visibly or they won't be printed.

Really, the usage of the filepicker is only the first part of the full macro what you needed. Then you must open (LoadFromURL...) the documents one by one (silently or visible) based on the picked path and the DIR strings as filenames, and then you will able to use the Print command of the API.
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.4; AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7965
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Postby OOKapitan » Thu Aug 24, 2017 9:10 am

Zizi64 wrote:
I tried. The macro allowes me to select the folder, but prints nothing. I forgot to say that the files must be opened visibly or they won't be printed.

Really, the usage of the filepicker is only the first part of the full macro what you needed. Then you must open (LoadFromURL...) the documents one by one (silently or visible) based on the picked path and the DIR strings as filenames, and then you will able to use the Print command of the API.

I do not no how to do this. Macro on the OpenOffice is a forest to me. I managed to write the macro I inserted two posts above by using parts of macro I found in the internet. In excel to write macro I in minimum just need to understand english. For macro in OpenOffice it doesn't work. Please help me to write full macro.
OpenOffice 3.3.0 on Windows 8.1
OOKapitan
 
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Postby Zizi64 » Thu Aug 24, 2017 11:59 am

Please help me to write full macro.


Read and study Andrew Pitonyak's free macro books:
http://www.pitonyak.org/oo.php

The forum is not a free macro writing service.

Try to write a macro, upload the working example here, and we will (try to) fix your mistakes.


In excel to write macro I in minimum just need to understand english. For macro in OpenOffice it doesn't work.

Try the LibreOffice. It has a higher compatibility with the foreign fileformats and the MS VBA macros.
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.4; AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7965
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests