Option Explicit

Sub ExportToHTML()
    Dim Filename As Variant
    Dim TDOpenTag As String, TDCloseTag As String
    Dim CellContents As String
    Dim Rng As Range
    Dim r As Long, c As Integer
    
'   Use the selected range of cells
    Set Rng = Application.Intersect(ActiveSheet.UsedRange, Selection)
    If Rng Is Nothing Then
        MsgBox "Nothing to export.", vbCritical
        Exit Sub
    End If
    
'   Get a file name
    Filename = Application.GetSaveAsFilename( _
        InitialFileName:="myrange.htm", _
        fileFilter:="HTML Files(*.htm), *.htm")
    If Filename = False Then Exit Sub
    
'   Open the text file
    Open Filename For Output As #1
    
'   Write the tags
    Print #1, ""
    Print #1, ""
    
'   Loop through the cells
    For r = 1 To Rng.Rows.Count
        Print #1, ""
        For c = 1 To Rng.Columns.Count
            Select Case Rng.Cells(r, c).HorizontalAlignment
                Case xlHAlignLeft
                    TDOpenTag = ""
            If Rng.Cells(r, c).Font.Bold Then
                TDOpenTag = TDOpenTag & ""
                TDCloseTag = "" & TDCloseTag
            End If
            If Rng.Cells(r, c).Font.Italic Then
                TDOpenTag = TDOpenTag & ""
                TDCloseTag = "" & TDCloseTag
            End If
            CellContents = Rng.Cells(r, c).Text
            Print #1, TDOpenTag & CellContents & TDCloseTag
        Next c
        Print #1, ""
    Next r
'   Close the table
    Print #1, "
" Case xlHAlignCenter TDOpenTag = "" Case xlHAlignGeneral If IsNumeric(Rng.Cells(r, c)) Then TDOpenTag = "" Else TDOpenTag = "" End If Case xlHAlignRight TDOpenTag = "" End Select TDCloseTag = "
" Print #1, "" ' Close the file Close #1 ' Tell the user MsgBox Rng.Count & " cells were exported to " & Filename End Sub