There is an easy way to convert a Word Document to a .htm web page by using Words Object Model .SaveAs method and specify the FileFormat argument of .wdFormatHTML



Word 2000 - 2003 and VB.NET 2005 - 2008

VB.NET Code:
  1. Option Explicit On
  2. Option Strict On
  3. 'Add a reference to Microsoft Office Word xx.0 Object Library
  4. 'Add a Button to your form (Button1)
  5. Imports Microsoft.Office.Interop
  6.  
  7. Public Class Form1
  8.  
  9.     Dim moApp As Word.Application
  10.  
  11.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  12.         Dim oDoc As Word.Document
  13.         Using OpenFileDialog1
  14.             With OpenFileDialog1
  15.                 .CheckFileExists = True
  16.                 .CheckPathExists = True
  17.                 .Filter = "Word Documents 2000-2003 Only (*.doc)|*.doc"
  18.                 .FilterIndex = 1
  19.                 .Multiselect = False
  20.                 .ShowReadOnly = False
  21.                 If .ShowDialog() = Windows.Forms.DialogResult.OK Then
  22.                     oDoc = DirectCast(moApp.Documents.Open(FileName:=.FileName.ToString), Word.Document)
  23.                     moApp.Visible = False ' or True if you want to show Word
  24.                     'Save the doc as the same file name but change the file extension to .htm
  25.                     oDoc.SaveAs(FileName:=.FileName.ToString.Replace(".doc", ".htm"), FileFormat:=Word.WdSaveFormat.wdFormatHTML)
  26.                     oDoc.Saved = True
  27.                     oDoc.Close(SaveChanges:=False)
  28.                     oDoc = Nothing
  29.                     'moApp.Visible = False 'If you choose to show Word in previous code
  30.                 End If
  31.             End With
  32.         End Using
  33.     End Sub
  34.  
  35.     Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  36.         If Not moApp Is Nothing Then
  37.             moApp.Quit()
  38.             moApp = Nothing
  39.         End If
  40.     End Sub
  41.  
  42.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  43.         Try
  44.             moApp = DirectCast(CreateObject("Word.Application"), Word.Application)
  45.         Catch ex As Exception
  46.             MessageBox.Show(ex.Message, "VB/Office Guru™ Word .NET Demo", _
  47.             MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  48.         End Try
  49.     End Sub
  50.  
  51. End Class