• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Save Text and Rich Text Files as HTML

Hello Everyone,

I have some text and rich text files I'd like to convert to html.  I can do this manually by opening the files with Internet Explorer and saving as HTML files.  I'd like to be able to do this in code, but with no prompting.  I've played around with IE's ExecWB, but it keeps prompting me for a file path.  I can do it through Word, but I hate the bloated HTML files Word creates.  Any suggestions?
1 Solution

You can open the files using MSWord (in background) and do the following:

    ChangeFileOpenDirectory "C:\MyFolder\"
    ActiveDocument.SaveAs FileName:="Doc1.htm", FileFormat:=wdFormatHTML, _
        LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
        :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
        SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    ActiveWindow.View.Type = wdWebView
svenswensonAuthor Commented:
Actually wdFormatFilteredHTML does a bit better, but this is what I ended up using:


I had to install the O2K HTML Filter on a machine with an old copy of O2K.  From there, I was able to copy over the files (mainly "MSFilter.dll") to my computer and then use the code in the example.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now