Macro to print documents in the same directory

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Macro to print documents in the same directory

Post by OOKapitan »

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
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Macro to print documents in the same directory

Post by JohnSUN-Pensioner »

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.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

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
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Post by Zizi64 »

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.

viewforum.php?f=53
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.
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

Ho is able easilly to write such mscro, please, write me this macros to me.
OpenOffice 3.3.0 on Windows 8.1
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Post by RoryOF »

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/Framew ... _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.15 on Xubuntu 22.04.4 LTS
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Post by RoryOF »

Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

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
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Post by RoryOF »

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.15 on Xubuntu 22.04.4 LTS
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

Who can write me the example of the macro?
OpenOffice 3.3.0 on Windows 8.1
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to print documents in the same directory

Post by Villeroy »

Shell command to send all ODF documents in D:\Data\PrintDocs\ to the default printer:

Code: Select all

soffice.exe -p D:\Data\PrintDocs\*.od?
Same with explicit printer name:

Code: Select all

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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

Villeroy wrote:Shell command to send all ODF documents in D:\Data\PrintDocs\ to the default printer:

Code: Select all

soffice.exe -p D:\Data\PrintDocs\*.od?
Same with explicit printer name:

Code: Select all

soffice.exe -pt PrinterName D:\Data\PrintDocs\*.od?
all in the derrictory the file with macro is?
PrinterName in

Code: Select all

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
User avatar
robleyd
Moderator
Posts: 5055
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Macro to print documents in the same directory

Post by robleyd »

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

Code: Select all

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
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

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
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Post by RoryOF »

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.15 on Xubuntu 22.04.4 LTS
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

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

Post by OOKapitan »

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
User avatar
robleyd
Moderator
Posts: 5055
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Macro to print documents in the same directory

Post by robleyd »

Use a .bat file, command prompt or even a shortcut icon.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to print documents in the same directory

Post by RoryOF »

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.15 on Xubuntu 22.04.4 LTS
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

Nevertheless, is anyone able to write the macro?
OpenOffice 3.3.0 on Windows 8.1
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Post by Zizi64 »

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.
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

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
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Post by Zizi64 »

Please upload your .ODF type file with the embedded macro code that you wrote.
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.
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

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 196 times
OpenOffice 3.3.0 on Windows 8.1
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Post by Zizi64 »

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

...
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; 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.
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

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
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Post by Zizi64 »

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; 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.
OOKapitan
Posts: 14
Joined: Mon Aug 14, 2017 2:24 pm

Re: Macro to print documents in the same directory

Post by OOKapitan »

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
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro to print documents in the same directory

Post by Zizi64 »

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; 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.
Post Reply