PDA

View Full Version : Sleeper: Amend HTML file



lifeson
08-28-2009, 01:36 AM
Hi folks
I am trying to create a large number of HTML files using data from a spreadsheet
The originl source.HTML file is this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Component Name</TITLE>
</HEAD>

<BODY>
<h1>Component Name</h1>
<img src="filename.gif" width="645" height="645">
</BODY>
</HTML>

I want to change the elements in red using the data from the spreadsheet where component name is in column A and the filename is in column B and then save as a simple component.html file

I can create the HTML string but how do I save the string as just an html file (not an excel html file)

rbrhodes
08-28-2009, 06:18 PM
Is component HTML not just text like HTML?

MaximS
08-30-2009, 04:40 AM
this will populate number of html files depending on size of your range



Private Sub html()
Dim meta As String, meta1 As String, meta2 As String
Dim header As String, body As String
Dim component As String, filename As String, html As String
Dim strDestFile As String, temp As String
Dim iFileNum As Integer, Lrow As Integer, i As Integer
' Set component and filename range as required
Lrow = ThisWorkbook.Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To Lrow
component = ThisWorkbook.Worksheets(1).Range("A" & i).Value
filename = ThisWorkbook.Worksheets(1).Range("B" & i).Value
meta = "<!DOCTYPE HTML PUBLIC " & Chr(34) & "-//W3C//DTD " _
& "HTML 4.0 Transitional//EN" & Chr(34) & ">"
header = "<HTML><HEAD><TITLE>" & component & "</TITLE></HEAD>"
body = "<BODY><h1>" & component & "</h1>" & "<img src=" & Chr(34) & _
filename & Chr(34) & " width=" & Chr(34) & "645" & Chr(34) & " height=" _
& Chr(34) & "645" & Chr(34) & "></BODY></HTML>"
' Set file destination if required
strDestFile = "c:\a\text.html"
iFileNum = FreeFile
Open strDestFile For Output As #iFileNum
' If an error occurs report it and end.
If Err <> 0 Then
MsgBox "Cannot open filename " & strDestFile
End
End If
Print #iFileNum, meta
Print #iFileNum, header
Print #iFileNum, body
Close #iFileNum
Next i
End Sub