Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset


Private Sub Command1_Click()
Dim fnum As Integer
Dim num_fields As Integer
Dim i As Integer
Dim num_processed As Integer

    fnum = FreeFile
    Open Text2.Text For Output As fnum

    Print #fnum, "<HTML>"
    Print #fnum, "<HEAD>"
    Print #fnum, "<TITLE>Convert Excel to HTML</TITLE>"
    Print #fnum, "</HEAD>"

    Print #fnum, "<TABLE ALIGN=CENTER WIDTH =100% CELLPADDING=2 CELLSPACING=2  BORDER=1>"

    con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\karthik\testfiles\bctest.xls;Extended Properties=Excel 8.0;Persist Security Info=False")
    Set rs = con.Execute("select * from [bctest$]")

    Print #fnum, " <TR BGCOLOR=#green>"
    num_fields = rs.Fields.Count
    For i = 0 To num_fields - 1
        Print #fnum, " <TH>";
        Print #fnum, rs.Fields(i).Name;
        Print #fnum, "</TH>"
    Next i
    Print #fnum, "</TR>"
 
    Do While Not rs.EOF
        num_processed = num_processed + 1
        Print #fnum, "<TR BGCOLOR=#99CCCC>";
        For i = 0 To num_fields - 1
            Print #fnum, "<TD>";
            Print #fnum, rs.Fields(i).Value;
            Print #fnum, "</TD>"
        Next i
        Print #fnum, "</TR>";

        rs.MoveNext
    Loop
    Print #fnum, "</TABLE>"
    
    Print #fnum, "<P>"
    Print #fnum, "<center>"
    Print #fnum, "<H3>" & _
        Format$(num_processed) & _
        " records displayed.</H3>"
  
    Print #fnum, "<h1><I><FONT COLOR= RED> THIS IS THE HTML FILE</font></I><h1>"
    Print #fnum, "</BODY>"
    Print #fnum, "</HTML>"
 
    rs.Close
    con.Close
    Close fnum
    MsgBox "Processed " & Format$(num_processed) & " records."

    Exit Sub

End Sub

Private Sub Form_Load()
    Text1.Text = "D:\karthik\testfiles\bctest.xls"
    Text2.Text = "D:\karthik\testfiles\bctest.htm"
End Sub