Gruppe
Extern
Problem
Aus einer Liste in den Spalten A:C soll ein hierarchisch aufgebautes Inhaltsverzeichnis als HTML-Datei aufgebaut werden.
StandardModule: Modul1
Sub CreateHTML()
Dim iRow As Integer, iStage As Integer, iCounter As Integer, iPage As Integer
Dim sFile As String
sFile = Application.DefaultFilePath & "\test.htm"
Close
Open sFile For Output As #1
Print #1, "<html>"
Print #1, "<head>"
Print #1, "<style type=""text/css"">"
Print #1, " body { font-size:12px;font-family:tahoma } "
Print #1, "</style>"
Print #1, "</head>"
Print #1, "<body>"
iRow = 2
Do While WorksheetFunction.CountA(Rows(iRow)) > 0
If Not IsEmpty(Cells(iRow, 1)) Then
For iCounter = 1 To iStage
Print #1, "</ul>"
iStage = iStage - 1
Next iCounter
Print #1, "<ul>"
Print #1, "<li><a href=""" & iPage & ".html"">" & Cells(iRow, 1).Value & "</a>"
iPage = iPage + 1
If iStage < 1 Then
iStage = iStage + 1
End If
End If
If Not IsEmpty(Cells(iRow, 2)) Then
For iCounter = 2 To iStage
Print #1, "</ul>"
iStage = iStage - 1
Next iCounter
Print #1, "<ul>"
Print #1, "<li><a href=""" & iPage & ".html"">" & Cells(iRow, 2).Value & "</a>"
iPage = iPage + 1
If iStage < 2 Then
iStage = iStage + 1
End If
End If
If Not IsEmpty(Cells(iRow, 3)) Then
If iStage < 3 Then
Print #1, "<ul>"
End If
Print #1, "<li><a href=""" & iPage & ".html"">" & Cells(iRow, 3).Value & "</a>"
iPage = iPage + 1
If iStage < 3 Then
iStage = iStage + 1
End If
End If
iRow = iRow + 1
Loop
For iCounter = 2 To iStage
Print #1, " </ul>"
iStage = iStage - 1
Next iCounter
Print #1, "</body>"
Print #1, "</html>"
Close
Shell "hh " & vbLf & sFile, vbMaximizedFocus
End Sub