Excel to Web Page
My stamp club decided that we needed to post our auction on the web a few days before the meeting.This macro takes the list they send me and converts into a tasteful table ready to upload to the web. I am using several loops and SELECT CASE to see if the row is Even or Odd. This combines my Excel VBA and HTML in one solution.
Sub MakeWebPage()
Dim LastCol As Long
Dim LastRow As Long
Dim TheTitle As String
Dim Quotes As String
Dim X As Long
Dim Y As Long
Dim TR, TD, eTR, ETD, clrTR
TR = " <tr class=" & Quotes & "whtrow" & Quotes & ">"
clrTR = " <tr class=" & Quotes & "contrastrow" & Quotes & ">"
TD = " <td>"
ETD = " </td>"
eTR = "</tr>"
Quotes = Chr(34)
Open "C:\alan-webs\auction.htm" For Output As #1
LastCol = Application.CountA(ActiveSheet.Range("1:1"))
LastRow = Application.CountA(ActiveSheet.Range("A:A"))
Print #1, "<!DOCTYPE HTML PUBLIC " & Quotes & "-//IETF//DTD HTML//EN" _
& Quotes & ">"
Print #1, "<html>"
Print #1, "<head>"
Print #1, "<link rel=" & Quotes & "shortcut icon" & Quotes & " href=" & Quotes & "favicon.ico" _
& Quotes & ">"
Print #1, "<meta http-equiv=" & Quotes & "Content-Type" & Quotes & " content=" _
& Quotes & "text/html; charset=iso-8859-1" & Quotes & ">"
Print #1, "<style type=" & Quotes & "text/css" & Quotes & ">"
Print #1, " .contrastrow"
Print #1, " {"
Print #1, " background-color: #ddffff;"
Print #1, " border-bottom-style: ridge;"
Print #1, " border-bottom-width: thick;"
Print #1, " vertical-align: top;"
Print #1, " }"
Print #1, " .whtrow"
Print #1, " {"
Print #1, " border-bottom-style: ridge;"
Print #1, " border-bottom-width: thick;"
Print #1, " vertical-align: top;"
Print #1, " }"
Print #1, "</style>"
TheTitle = InputBox("What is the page Title? Date of Auction?", "Page Title", "Auction - ")
Print #1, "<title>" & TheTitle & "</title>"
Print #1, "</head>" & vbCrLf & "<body>"
Print #1, "<h1>" & TheTitle & "</h1>"
Print #1, "<table width=" & Quotes & "100%" & Quotes & " border=" & Quotes & "1" _
& Quotes & ">"
Print #1, " <tr>"
For Y = 1 To LastCol
Print #1, "<th>" & Cells(1, Y) & "</th>"
Next Y
Print #1, eTR
For X = 2 To LastRow
Select Case X Mod 2
Case 1
Print #1, clrTR
For Y = 1 To LastCol
Print #1, TD & Cells(X, Y) & ETD
Next Y
Print #1, eTR
Case Else
Print #1, TR
For Y = 1 To LastCol
Print #1, TD & Cells(X, Y) & ETD
Next Y
Print #1, eTR
End Select
Next X
Print #1, "</table>"
Print #1, "<p><a href=" & Quotes & "auction.xls" & Quotes & "
>Get spreadsheet</a></p>"
Print #1, "<p>Updated: " & Application.Text(Now(), _
"dd mmmm, yyyy HH:mm") & "</p>"
Print #1, " </body>" & vbCrLf & "</html>"
Close #1
MsgBox "Done with " & LastRow & " items"
End Sub
Check out the fruits of my labor at Webster Grove Stamp Club.
|