Gruppe
Extern
Problem
Wie kann ich alle Dateien eines anzugebenden Verzeichnisses in einer HTML-Datei auflisten und einen Link zu ihnen erstellen lassen?
StandardModule: basMain
Sub Dir2HTML()
Dim iCounter As Integer, iFile As Integer
Dim sPath As String, sFile As String
iFile = FreeFile
sPath = Range("B1").Value
sFile = Range("B2").Value
On Error GoTo ERRORHANDLER
Open sFile For Output As iFile
Print #iFile, "<html>"
Print #iFile, "<head>"
Print #iFile, "<title>Dateien im Verzeichnis " & sPath & "</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><th colspan=2 bgcolor=#ffffe0>" & _
"Dateiliste des Ordners " & sPath & "</th></tr>"
Print #iFile, "<tr><th align=left>Dateidatum</th>" & _
"<th align=left>Dateiname</th></tr>"
With Application.FileSearch
.LookIn = sPath
.Execute
For iCounter = 1 To .FoundFiles.Count
Print #iFile, "<tr><td>" & _
FileDateTime(.FoundFiles(iCounter)) & _
"</td><td>" & _
"<a href=""" & .FoundFiles(iCounter) & """>" & _
.FoundFiles(iCounter) & _
"</a></td></tr>"
Next iCounter
End With
Print #iFile, "</table>"
Print #iFile, "</body>"
Print #iFile, "</html>"
Close iFile
Shell "explorer " & sFile, vbMaximizedFocus
Exit Sub
ERRORHANDLER:
MsgBox "Die HTML-Datei konnte nicht angelegt werden!"
End Sub