John Clarkson
Microsoft Corporation
August 1999
Summary: This tip describes how to programmatically convert Word 97 documents to HTML files. (2 printed pages)
This tip describes how to programmatically convert Microsoft® Word 97 documents to HTML files. It's possible to come up with some quick-and-dirty code to do this by referring to the HTML member of the FileConverters collection, or by using the Save As HTML (File menu) command while recording a macro. However, both of these temporary solutions rely on settings that vary from machine to machine. You can't successfully port the code to a second machine without finding the values specific to the new environment and using these values to edit your code accordingly. To find a portable HTML conversion solution, you need code that loops through the FileConverters collection looking for the right converter. When the converter is found, use it as the value of the FileFormat argument of the SaveAs method, and exit the loop. The following procedure does just that.
Sub HTMLSave()
' This procedure steps through the FileConverters collection
' looking for the HTML converter, and then converts the current file.
Dim wrdConverter As FileConverter
Dim strMessage As String
Dim strPath As String
'Get a name and location for the converted file.
strMessage = "Enter a path and file name for the converted file."
strPath = InputBox(strMessage)
For Each wrdConverter In Word.FileConverters
'If found, Save As, then exit the loop.
If wrdConverter.ClassName = "HTML" Then
ActiveDocument.SaveAs _
FileName:=strPath, _
FileFormat:=wrdConverter.SaveFormat
Exit For
End If
Next wrdConverter
End Sub
Understand that there are limitations to any automated conversion. Note that if you use this solution: