Excel to HTML Macro
A simple and handful macro to convert your Excel data into a HTML
table.
The chosen field or cells are saved as HTML table into browser (Chrome etc.).
View of browser : ⤵
Macro can be operated by pressing the button on sheet. Or the macro named Convert is selected and executed from the Macro window opened by pressing + keys on keyboard.
VBA codes of Conver Macro :
Sub Convert()
Dim Dosya, Tag_Ac$, Tag_Kapat$, Cells$, Evn As Range, i%, a%
Set Evn = Application.Intersect(ActiveSheet.UsedRange, Selection)
If Evn Is Nothing Then MsgBox "Please Select Area", 16: Exit Sub
Dosya = Application.GetSaveAsFilename(InitialFileName:="Sample-file.html", _
fileFilter:="HTML Files(*.html), *.html")
If Dosya = False Then Exit Sub
Open Dosya For Output As #1
Print #1, "<HTML>"
Print #1, "<TABLE BORDER=1 CELLPADDING=3>"
For i = 1 To Evn.Rows.Count
Print #1, "<TR>"
For a = 1 To Evn.Columns.Count
Select Case Evn.Cells(i, a).HorizontalAlignment
Case xlHAlignLeft
Tag_Ac = "<TD ALIGN=LEFT>"
Case xlHAlignCenter
Tag_Ac = "<TD ALIGN=CENTER>"
Case xlHAlignGeneral
If IsNumeric(Evn.Cells(i, a)) Then
Tag_Ac = "<TD ALIGN=RIGHT>"
Else
Tag_Ac = "<TD ALIGN=LEFT>"
End If
Case xlHAlignRight
Tag_Ac = "<TD ALIGN=RIGHT>"
End Select
Tag_Kapat = "</TD>"
If Evn.Cells(i, a).Font.Bold Then
Tag_Ac = Tag_Ac & "<B>"
Tag_Kapat = "</B>" & Tag_Kapat
End If
If Evn.Cells(i, a).Font.Italic Then
Tag_Ac = Tag_Ac & "<I>"
Tag_Kapat = "</I>" & Tag_Kapat
End If
Cells = Evn.Cells(i, a).Text
Print #1, Tag_Ac & Cells & Tag_Kapat
Next a
Print #1, "</TR>"
Next i
Print #1, "</TABLE>"
Print #1, "</HTML>"
Close #1
MsgBox Evn.Count & " Cells were exported here : " & Dosya
End Sub
Dim Dosya, Tag_Ac$, Tag_Kapat$, Cells$, Evn As Range, i%, a%
Set Evn = Application.Intersect(ActiveSheet.UsedRange, Selection)
If Evn Is Nothing Then MsgBox "Please Select Area", 16: Exit Sub
Dosya = Application.GetSaveAsFilename(InitialFileName:="Sample-file.html", _
fileFilter:="HTML Files(*.html), *.html")
If Dosya = False Then Exit Sub
Open Dosya For Output As #1
Print #1, "<HTML>"
Print #1, "<TABLE BORDER=1 CELLPADDING=3>"
For i = 1 To Evn.Rows.Count
Print #1, "<TR>"
For a = 1 To Evn.Columns.Count
Select Case Evn.Cells(i, a).HorizontalAlignment
Case xlHAlignLeft
Tag_Ac = "<TD ALIGN=LEFT>"
Case xlHAlignCenter
Tag_Ac = "<TD ALIGN=CENTER>"
Case xlHAlignGeneral
If IsNumeric(Evn.Cells(i, a)) Then
Tag_Ac = "<TD ALIGN=RIGHT>"
Else
Tag_Ac = "<TD ALIGN=LEFT>"
End If
Case xlHAlignRight
Tag_Ac = "<TD ALIGN=RIGHT>"
End Select
Tag_Kapat = "</TD>"
If Evn.Cells(i, a).Font.Bold Then
Tag_Ac = Tag_Ac & "<B>"
Tag_Kapat = "</B>" & Tag_Kapat
End If
If Evn.Cells(i, a).Font.Italic Then
Tag_Ac = Tag_Ac & "<I>"
Tag_Kapat = "</I>" & Tag_Kapat
End If
Cells = Evn.Cells(i, a).Text
Print #1, Tag_Ac & Cells & Tag_Kapat
Next a
Print #1, "</TR>"
Next i
Print #1, "</TABLE>"
Print #1, "</HTML>"
Close #1
MsgBox Evn.Count & " Cells were exported here : " & Dosya
End Sub
No comments:
Post a Comment