PDA

View Full Version : [SOLVED:] convert content of wordfile to html



kenan
09-01-2014, 02:52 AM
hi everyone,

I am trying to convert content of word-file to html-file. The converting must be page by page with vba. for the converting is used following code.


*****************Beginn code: **********************
Dim wdNewDoc As Document
Dim appMsWord As Application


'tempFileName = ActiveDocument.Path & "\" & Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1) & ".HTM"
'TODO: benutzte dasselbe Dokument, falls das Dokument bereits existiert...
Set wdNewDoc = Documents.Add(Template:=ActiveDocument.AttachedTemplate.FullName)


With wdNewDoc
.ActiveWindow.WindowState = wdWindowStateMinimize
.Range(0, 0).Select
.content.FormattedText = objRange.FormattedText
.SaveAs tempFilename, wdFormatFilteredHTML
.Close
End With

************** end code ***************************************

The problem: it is very slow, if i am trying to convert page by page content of wordfile to html. for every page will be opened a new document window. I am trying to use the same document window, but i can not acces the html formatted file. Because the file is locked by ms office.

Do anybody know, how can I access read-only access a file, that already opened by ms office? or any better idea, how can I convert content of word file to html(it muste be page by page)

thanks!

gmayor
09-01-2014, 05:01 AM
You could use my Batch processing add-in (http://www.gmayor.com/document_batch_processes.htm) (even for a single file) to run a custom process. It handles all the background tasks related the file handling and will produce the same end result that your macro produces, albeit without seeing the document being processed. Use it to run the following custom process:


Function SaveHTML(oDoc As Document) As Boolean
Dim oNewDoc As Document
Dim strNewName As String
On Error GoTo Err_Handler
Set oNewDoc = Documents.Add(Template:=oDoc.FullName, Visible:=False)
oNewDoc.Content.FormattedText = oDoc.Range.FormattedText
strNewName = oDoc.FullName
strNewName = Left(strNewName, InStrRev(strNewName, Chr(46)))
strNewName = strNewName & "html"
oNewDoc.SaveAs Filename:=strNewName, _
FileFormat:=wdFormatFilteredHTML, _
AddToRecentFiles:=False
oNewDoc.Close 0
SaveHTML = True
lbl_Exit:
Exit Function
Err_Handler:
SaveHTML = False
End Function