Save Text and Rich Text Files as HTML

Posted on 2005-05-11
Last Modified: 2010-05-01
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?
Question by:svenswenson
    LVL 2

    Accepted 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

    Author Comment

    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now