Excel VBA to make HTML table


Option Explicit

' write HTML

Sub sbWriteHTML()
 Dim iRows, iColumns, iRow, iColumn, iHeader As Long
 Dim sValue, sHTML, sText As String
 Dim rSelectedRange As Range
 Set rSelectedRange = Application.Selection
 iColumns = rSelectedRange.Columns.Count
 iRows = rSelectedRange.Rows.Count
 sHTML = ""
 For iRow = 1 To iRows
  For iColumn = 1 To iColumns
   sText = Cells(iRow, iColumn).Text
   sHTML = sHTML & ""
  Next iColumn
  sHTML = sHTML & "" ' & vbCrLf
 Next iRow
 sHTML = sHTML & "
" & sText & "
" CreateObject("htmlfile").ParentWindow.ClipboardData.SetData "text", sHTML End Sub