OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Macro for batch converting WP files.

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
cwchia
Super User
Super User


Joined: 09 Jan 2003
Posts: 1050
Location: Malaysia

PostPosted: Thu Apr 03, 2003 5:25 pm    Post subject: Macro for batch converting WP files. Reply with quote

As said in my earlier post in this forum, I was using a 'low tech' get around way to convert my old WP files to SO 5.2 (using SO 5.2 as it has WP filter) then again to convert it to OOo 1.0.2 using OOo 1.0.2. Teadious isn't it?

Can anyone help by writing a macro for batch conversion ( so that I can use it on SO 5.2 which I still have a copy of it and then again use the same macro to perform the 2nd conversion under OOO)?

Your help is greatly appreciated as I am still not clear about how to write such macro.

Thanks
Back to top
View user's profile Send private message
dfrench
Moderator
Moderator


Joined: 03 Mar 2003
Posts: 1605
Location: Wellington, New Zealand

PostPosted: Sat Apr 05, 2003 10:06 pm    Post subject: Reply with quote

Maybe this will help ... can;t test any of this as I do not have SO or WP files
I am assuming
1.you have a heap of WP files in a directory/folder or many folders
2. If you open a WP file in SO it is automatically processed through the filter to give a standard document object
3. If you save that document as normal SO document file then you can read it in OOo

Macro logic ..
1. Set up directory/folder and WP file extension
2. Loop aroud files in directory with that extension until no more files
>>For each file
>>found open it
>>get the filename and create new file name to save the doc as from it
>>save as with appropriate filter spec

Untested code follows
Code:

sub cvtwps
rem takes all .sxw files from chosen directory and writes .pdf files to anotyher chosen directory
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
dim sInDir as string
dim sOutDir as string
dim sFile as string
dim sUrl as string
dim spdf as string
dim doct as object   
Dim args(0) as new com.sun.star.beans.PropertyValue
dim args1(2) as new com.sun.star.beans.PropertyValue
Dim mFileProperties(1) As New com.sun.star.beans.PropertyValue
dim mNoArgs() ' supplies empty arg list
' get the input and output directories for the document source and pdf output
sInDir = InputBox("Input Directory","Macro Dialog","file:///c|/Temp/pdftest/")
sOutDir = InputBox("Output Directory","Macro Dialog","file:///C|/Temp/pdftest/")
' DIR basic runtime sets directory and returns first filename
sFile = Dir(sInDir+"*.xxx")  ' can be any valid selection for file namesnnnn
' set up interfaces required

oDesktop = createUnoService("com.sun.star.frame.Desktop")
'could set a  property for silent ie no visible document operation
args(0).Name = "ReadOnly"
args(0).Value = True
While sFile <> ""  ' loop while there are files to process in input directory
   sUrl = sIndir+sfile
   ' load doc by name
   
   doct=oDesktop.loadComponentFromURL(sURL,"_blank",0,Args())
   
   rem ----------------------------------------------------------------------
   ' output file name  replace the .xxx with .sxw
   spdf =sOutDir+ left(sfile,len(sfile)-4)+".sxw"
   rem ----------------------------------------------------------------------
    'set properties

   sUrl = spdf
   mFileProperties(0).Name = "Overwrite"
   mFileProperties(0).Value = FALSE
   mFileProperties(1).Name = "FilterName"
   mFileProperties(1).Value = "StarOffice XML (Writer)"  'from recording macro on OOo
' store as
   doct.storeAsURL(sUrl, mFileProperties())
   ' unload the document object
   doct.dispose()
   ' get next filename  null when none left
   sfile = dir
wend
end sub
All from StarOffice Programmerís Tutorial and starbasic help in OOo
all care no responsibility
Back to top
View user's profile Send private message
cwchia
Super User
Super User


Joined: 09 Jan 2003
Posts: 1050
Location: Malaysia

PostPosted: Sun Apr 06, 2003 9:26 pm    Post subject: Reply with quote

Thanks. Shall try to tinkle around.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group