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

Creating a macro - Writing a Script - Using the API

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

Postby harryspier » Fri Nov 28, 2014 2:58 am

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
harryspier
 
Posts: 21
Joined: Fri Feb 01, 2013 9:24 pm

Re: Applying a macro to all files in a directory

Postby FJCC » Fri Nov 28, 2014 5:05 am

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
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7263
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Applying a macro to all files in a directory

Postby harryspier » Sat Nov 29, 2014 3:51 pm

Thank you for this. That should get me going.

Regards,
Harry
OpenOffice 3.4.1 Windows 8
harryspier
 
Posts: 21
Joined: Fri Feb 01, 2013 9:24 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests