Consulting

Results 1 to 2 of 2

Thread: convert content of wordfile to html

  1. #1
    VBAX Newbie
    Joined
    Sep 2014
    Posts
    4
    Location

    convert content of wordfile to html

    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!

  2. #2
    You could use my Batch processing add-in (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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •