• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Save a range as HTML Table

If you want to save a range as HTML table on HTML webpage. Here is the code


Download Working File https://www.box.com/s/7h58p020dasqcp01ayov

[pre]
Code:
Sub send_range_as_html_table()

‘  used to insert a line ( press enter)
‘ create a table using html
‘ check the link below to know more about html tables
‘ http://www.w3schools.com/html/html_tables.asp
‘ html color code
‘http://www.computerhope.com/htmcolor.htm or http://html-color-codes.info/
‘bg color is used for background color
‘ font color is used for font color
‘<b> bold the text http://www.w3schools.com/html/html_formatting.asp
‘   is used to give a single space between text
‘<p style=”font-size:15px”>This is some text!</p> used to reduce for font size

Dim mbody As String, mbody1 As String
Dim rng As Range
Dim i As Long
Dim j As Long

‘ SET RANGE
Set rng = Sheets(1).Range(“a1:c9″)
fl_nm = “C:Documents and SettingsuserDesktopNew Songsexport_excel_range_table.html”
mbody = “<TABLE Border=”"1″”, Cellspacing=”"0″”><TR>”
‘Header row

For i = 1 To rng.Columns.Count
mbody = mbody & “<TD Bgcolor=”"#F08080″”, Align=”"Center”"><Font Color=#483D8B><b><p style=”"font-size:18px”">” & rng.Cells(1, i).Value & “ </p></Font></TD>”
Next

For i = 2 To rng.Rows.Count
mbody = mbody & “<TR>”
mbody1 = “”
For j = 1 To rng.Columns.Count
mbody1 = mbody1 & “<TD><center>” & Sheets(1).Cells(i, j).Value & “</TD>”
Next
mbody = mbody & mbody1 & “</TR>”
Next

Open fl_nm For Output As #1
Print #1, mbody
Close #1

End Sub
[/pre]
Download Working File https://www.box.com/s/7h58p020dasqcp01ayov
 
Back
Top