[Solved] Applying a macro to all files in a directory

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
harryspier
Posts: 21
Joined: Fri Feb 01, 2013 9:24 pm

[Solved] Applying a macro to all files in a directory

Post by harryspier »

I have a basic macro that processes a document that is opened in OpenOffice. But I have to process tens of thousands of documents. Can anyone point me to a script that opens each file in a directory, runs a macro and saves the file in another directory.

Thanks,
Harry Spier
Last edited by harryspier on Sat Nov 29, 2014 10:27 pm, edited 1 time in total.
OpenOffice 3.4.1 Windows 8
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Applying a macro to all files in a directory

Post by FJCC »

Here is a rough version. I check if the file name ends in ods because my desktop has all kinds of files.

Code: Select all

directory = "C:\Users\fjcc\Desktop\"
newDirectory = "C:\Users\fjcc\Desktop\TargetFolder\"
file = DIR(directory)
While file <> ""
	If RIGHT(file,3) = "ods" Then
		fileURL = convertToURL(directory & file)
		oDoc = StarDesktop.loadComponentFromURL(FileURL, "_blank", 0, Array())
		'do stuff here
		oDoc.storeAsURL(convertToURL(newDirectory & file), Array())
		oDoc.close(TRUE)
	End If
file = DIR()
WEnd
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
harryspier
Posts: 21
Joined: Fri Feb 01, 2013 9:24 pm

Re: Applying a macro to all files in a directory

Post by harryspier »

Thank you for this. That should get me going.

Regards,
Harry
OpenOffice 3.4.1 Windows 8
Post Reply