Creating HTM file via Excel VBA

This post VBA code never been used in final application by me – but in test files it was used. I’ve spent a little bit time on it. Code is quite interesting becasue of HTML tags used inside to create HTM file that is being opening in internet browser.

Creating HTM file guarantees as the same schema (should be) for all workstations. Plik HTM has been created be me when PDF SAVE AS tool has not been a part of Excel.

Following sources have been used to create HTM file:
1. Create HTM files from sheet data
2. Extension filters for saving files
3. Different table styles in CSS
4. Font size in CSS
5. Polish signs in Firefox

For tests some data have to be added to active sheet – the best as in following image:

How to create HTM file:

' Source:
' Create HTM files from sheet data
' Extension filters for saving files
' Different table styles in CSS
' Font size in CSS
' Polish signs in Firefox

Sub HTM_Page_Creation()

Dim TempStr
Dim PageName As String
Dim MyFormats As Variant
Dim FirstRow, LastRow, FirstCol, LastCol, MyRow, MyCol As Integer

' ----------------------------------

PageName = Application.GetSaveAsFilename("HTM_File_Name", "HTM file (*.htm), *.htm", 1, "Save raport")
' Checking if user chosen CANCEL action
If PageName = "False" Then
    MsgBox "CANCELED.", vbOKOnly + vbInformation, "CONFIRMATION..."
    Exit Sub
End If

' ----------------------------------

' MyFormats is an array which can contain formats for numbersand dates. Add one element for each table column.
MyFormats = Array("#", "dd mmm yy", "# ##0 pln", "0%")

' HTM table range
FirstRow = 1
LastRow = 6
FirstCol = 1
LastCol = 4

' ----------------------------------
' CHECKING DATA CORRECTION (admit I don't know how it works)

'If error macro is stopped
'If UBound(MyFormats2) < (LastCol - FirstCol) Then
'    MsgBox "No data - code has been stopped", vbOKOnly + vbCritical, "HTM Creation..."
'    Exit Sub
'End If

' ----------------------------------

Open PageName For Output As #1
Print #1, "<html>"
Print #1, "<head>"
Print #1, "<title>COMPANY SALE RAPORT</title>" ' is showing in browser tab
Print #1, "<meta http-equiv='content-type' content='text/html;charset=windows-1250' />" ' polish signs in Forefox
Print #1, "<style type='text/css'>"
Print #1, "body {font-family: Arial, Helvetica; font-size: 11pt; margin-left: 10; margin-right: 10}"
Print #1, "td.td1 {padding: 1pt 3pt 2pt 3pt; border-style: solid; border-width: 1; border-color: #0F5BB9; font-size: 11pt}"
Print #1, "table.table1 {border-collapse: collapse; border-width: 1 ; border-style: solid; border-color: #0F5BB9 }"
Print #1, "p.p1 {font-size: 8pt}"
Print #1, "</style>"
Print #1, "</head>"

Print #1, "<body>"
Print #1, "<h1>PAGE TITLE</h1>"
Print #1, "<p></p>"
Print #1, "<table class='table1'>"
Print #1, "<p></p>"

' Adding data to HTM files
For MyRow = FirstRow To LastRow
    Print #1, "<tr>"
    For MyCol = FirstCol To LastCol
            If MyRow = 1 Then
                TempStr = Cells(MyRow, MyCol).Value
                TempStr = "<b>" & TempStr & "</b>"
                TempStr = "<td class='td1'; align='center'; bgcolor='#58FAF4'>" & TempStr & "</td>"
                If IsNumeric(Cells(MyRow, MyCol).Value) = True Then
                    TempStr = Format(Cells(MyRow, MyCol).Value, MyFormats(MyCol - FirstCol))
                    TempStr = "<td class='td1'; align='right'>" & TempStr & "</td>"
                    TempStr = Cells(MyRow, MyCol).Value
                    TempStr = "<td class='td1'; align='left'>" & TempStr & "</td>"
                End If
            End If
        Print #1, TempStr
    Next MyCol
    Print #1, "</tr>"
Next MyRow

Print #1, "</table>"

' HTM file finalization
Print #1, "<p></p>"
Print #1, "<p class='p1'>To search some value use [CTRL]+'F'. Press[Home] to"
Print #1, "back on top. Data might be copied to Excel</p>"
Print #1, "<hr>"

Print #1, "<p><small>Raport date: " & Format(Date, "dd-mm-yyyy") & " | <a href=''>File has been created thanks to  meadinkent</a></small></p>"
Print #1, "<p></p>"
Print #1, "<p><img src='Some image path'></p>"
Print #1, "</body>"
Print #1, "</html>"
Close #1

MsgBox "Done"

End Sub

124 thoughts on “Creating HTM file via Excel VBA

  1. Pingback: tangerine business account online

  2. Pingback: nằm mơ thấy con chí

  3. Pingback: mo thay cho chet

  4. Pingback: ป๊อกเด้งออนไลน์

  5. Pingback: nằm mơ thấy thỏ

  6. Pingback: mơ thấy xe máy đánh con gì

  7. Pingback: gamescheat

  8. Pingback: cây phong thuỷ phòng làm việc

  9. Pingback: cung song tử hợp với cung nào nhất

  10. Pingback: con gái thiên bình

  11. Pingback: mơ thấy mất xe đạp

  12. Pingback: mơ thấy quay lại với người yêu cũ

  13. Pingback: mơ thấy đứt tay

  14. Pingback: danh bai doi thuong tren pc

  15. Pingback: game dua ngua dat cuoc

  16. Pingback: ดูหนังออนไลน์เต็มเรื่อง

  17. Pingback: Bilåtervinnare Göteborg

  18. Pingback: mơ thấy quả bưởi đánh con gì

  19. Pingback: mơ thấy đồ ăn

  20. Pingback: chiem bao thay di chua

  21. Pingback: mơ ăn chuối

  22. Pingback: mơ bốc mộ

  23. Pingback: nằm mơ thấy tóc rụng

  24. Pingback: mơ chụp ảnh

  25. Pingback:

  26. Pingback: Sicherheitsdienst

  27. Pingback: Tyson vs Jones jr live stream

  28. Pingback: cvv dumps with pin

  29. Pingback:

  30. Pingback: pasarqq

  31. Pingback: buy real drivers license uk

  32. Pingback: Market Retailers

  33. Pingback: ตู้แปลภาษา

  34. Pingback: ดูการ์ตูนออนไลน์ อนิเมชั่น

  35. Pingback: mơ đánh chết người

  36. Pingback: mơ thấy cá lóc

  37. Pingback: mơ bị sét đánh

  38. Pingback: bị bọ cạp cắn

  39. Pingback: Boka hämtning skrotbil

  40. Pingback: mơ thấy nhà mới đánh con gì

  41. Pingback: mo thay toc

  42. Pingback: read this post here

  43. Pingback: 토토사이트

  44. Pingback: rescator su

  45. Pingback: evdamhft

  46. Pingback: what makes viagra work

  47. Pingback: wat is viagra voor mannen

  48. Pingback: how long does it take azithromycin to enter you system

  49. Pingback: cialis and viagra

  50. Pingback: viagra

  51. Pingback: comprar viagra

  52. Pingback: quick essay writing service

  53. Pingback: write my research paper reddit

  54. Pingback: writing my essay

  55. Pingback: help me in essay writing

  56. Pingback: business essay writing

  57. Pingback: augmentin generic brand

  58. Pingback: where can i get furosemide

  59. Pingback: azithromycin brand name in india

  60. Pingback: ivermectin stromectol

  61. Pingback: ventolin australia

  62. Pingback: acne pills doxycycline

  63. Pingback: prednisolone 5mg price

  64. Pingback: reviews on clomid

  65. Pingback: dapoxetine 30mg reviews

  66. Pingback: diflucan toenail fungus

  67. Pingback: synthroid weight

  68. Pingback: propecia shedding pictures

  69. Pingback: neurontin impotence

  70. Pingback: metformin hydrochloride

  71. Pingback: paxil and oxycodone

  72. Pingback: sanofi aventis plaquenil

  73. Pingback: metformin 500 mg otc

  74. Pingback: propecia

  75. Pingback: where to buy finasteride

  76. Pingback: ordering cialis online australia

  77. Pingback: medication for ed dysfunction

  78. Pingback: medication canadian pharmacy

  79. Pingback: buy cialis cheaper online

  80. Pingback: Zakhar Berkut hd

  81. Pingback: 4569987

  82. Pingback: buy cialis in miami

  83. Pingback: cialis 20mg usa

  84. Pingback: how to buy cialis online uk

  85. Pingback: buy insurance

  86. Pingback: news news news

  87. Pingback: ordering online australia

  88. Pingback: psy

  89. Pingback: psy2022

  90. Pingback: projectio-freid

  91. Pingback: best payday loans turlock

  92. Pingback: Tinder Says I Have A Message But I Can't See It

  93. Pingback:

  94. Pingback: topvideos

  95. Pingback: video

  96. Pingback: viagra with alcohol

  97. Pingback: lisinopril 20mg online

  98. Pingback:

  99. Pingback: Ukrainskie-serialy

  100. Pingback: site

  101. Pingback: generic cialis pricing

  102. Pingback: cialis v viagra

  103. Pingback: top

  104. Pingback: cialist the yeloow pill

  105. Pingback: canada cialis online

  106. Pingback: canadian online pharmacy calls

  107. Pingback: cost of cialis without insurance

  108. Pingback: viagra vs cialis vs levitra price

  109. Pingback: best rx online pharmacy

  110. Pingback: buy cialis without perscription

  111. Pingback: cialis online without prescription

  112. Pingback: cialis without presciption in usa

  113. Pingback: declaring prescription drugs us customs

  114. Pingback: buy cialis online viagra

  115. Pingback: where can i buy cialis without a prescription

  116. Pingback: ed medicines

  117. Pingback: valtrex 250 mg 500 mg

  118. Pingback: erectile dysfunction medicines

  119. Pingback: cause of ed

  120. Pingback: viagra without a doctor prescription usa

  121. Pingback: cialis brand name

  122. Pingback: sildenafil viagra 100mg

  123. Pingback:

Leave a Reply

Your email address will not be published. Required fields are marked *