Gruppe
Extern
Problem
Wie kann ich aus einer Tabelle nur die Zeilen in eine HTML-Datei konvertieren, in denen eine Zelle einen bestimmten Inhalt hat?
StandardModule: basMain
Sub BedingtZuHTML()
Dim rng As Range
Dim var As Variant
Dim iRow As Integer, iCol As Integer, iFile As Integer
Dim sFile As String
Set rng = Range("A1").CurrentRegion
iFile = FreeFile
sFile = Application.Path & "\testhtml.htm"
Open sFile For Output As iFile
Print #iFile, "<html>"
Print #iFile, "<head>"
Print #iFile, "<title>Bedingte HTML-Übernahme</title>"
Print #iFile, "<style>"
Print #iFile, " th"
Print #iFile, " {"
Print #iFile, " font-family=tahoma,verdana;"
Print #iFile, " font-size=12px;"
Print #iFile, " font-weight=bold"
Print #iFile, " }"
Print #iFile, ""
Print #iFile, " td"
Print #iFile, " {"
Print #iFile, " font-family=tahoma,verdana;"
Print #iFile, " font-size=12px;"
Print #iFile, " }"
Print #iFile, "</style>"
Print #iFile, "<head>"
Print #iFile, "<body>"
Print #iFile, "<table border=1 cellpadding=3 cellspacing=1>"
Print #iFile, " <tr>"
For iCol = 1 To rng.Columns.Count
Print #iFile, " <th bgcolor=#ffffe0>" & Cells(1, iCol).Value & "</th>"
Next iCol
Print #iFile, " </tr>"
For iRow = 1 To rng.Rows.Count
var = Application.Match("Zu HTML", Rows(iRow), 0)
If Not IsError(var) Then
Print #iFile, " <tr>"
For iCol = 1 To rng.Columns.Count
Print #iFile, " <td>" & Cells(iRow, iCol).Value & "</td>"
Next iCol
Print #iFile, " </tr>"
End If
Next iRow
Print #iFile, "</table>"
Print #iFile, "</body>"
Print #iFile, "</html>"
Close iFile
Shell "explorer " & sFile, vbMaximizedFocus
End Sub