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

Posted:
Fri Nov 28, 2014 2:58 am
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
Re: Applying a macro to all files in a directory

Posted:
Fri Nov 28, 2014 5:05 am
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 Expand viewCollapse view
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
Re: Applying a macro to all files in a directory

Posted:
Sat Nov 29, 2014 3:51 pm
by harryspier
Thank you for this. That should get me going.
Regards,
Harry