How to open 500+ docs and save as .html

Hi.
I’m having 500+ .doc files to save as html. i’ve started to write a Macro using bits and pieces found there but what I manage to do is to save 500 times the same document.
Is there anybody clever?
(This is my first ever attempt at writing a Macro and hopefully my last)

Here’s what i painfully wrote:

Sub ExportAllDocsToHTML()
Dim vEnumerate 'Enumeration object
Dim vComp 'Single component
Dim s As String 'Display string
Dim sURL As String 'Document URL
GlobalScope.BasicLibraries.LoadLibrary(“Tools”) ’ Only for GetFileName
vComps=StarDesktop.getComponents()'com.sun.star.container.XEnumerationAccess

vEnumerate = vComps.createEnumeration() 'com.sun.star.container.XEnumeration
Do While vEnumerate.hasMoreElements()   'Are there any elements to retrieve?
vComp = vEnumerate.nextElement()
    If HasUnoInterfaces(vComp, "com.sun.star.frame.XModel") Then
      sURL = vComp.getURL()
      If sURL = "" Then
        s = s & "<Component With No URL>" & CHR$(10)
      Else
            ' function below will convert to htrml
      	SubSaveasHTML(sURL)
        s = s & FileNameOutOfPath(sURL) & CHR$(10)
       	vComp.close(true) 'close open doc
      End If
    End If
Loop	  	 
MsgBox s, 0, "Files processed"

End Sub

Function SubSaveasHTML(byval sURL)
if sURL= “” then
MsgBox sURL, 0, “Not valid”
exit function
end if

Dim FileN As String ' URL of target CSV-file
Dim oCurrentController As Object ' Before save - activate sheet sSheetName
Dim storeParms(1) as new com.sun.star.beans.PropertyValue 
   GlobalScope.BasicLibraries.LoadLibrary("Tools") ' Only for GetFileName
   FileN = GetFileNameWithoutExtension(sURL) & ".html"
   storeParms(0).Name = "FilterName"
   storeParms(0).Value = "HTML (StarWriter)" 
   storeParms(1).Name = "Overwrite"
   storeParms(1).Value = True 

   thisComponent.CurrentController.Frame
   thisComponent.storeToURL(FileN,storeParms())
       ConvertFromUrl(FileN) + """.")

End Function

Any help would be appreciated
Thks
RT

Hi @Remi,

I haven’t had a chance to look over your code yet, but would it be possible for you to just do the conversion on the command line? Something like this should work:

soffice --headless --convert-to html:HTML myfile.doc

Or for multiple files in a directory:

soffice --headless --convert-to html:HTML *.doc

For more information about command line conversion, take a look at @jopenid’s answer to this question:

And here’s an example from @w_whalley of iterating over many files using the find command:

@remi – Does my answer work for you?