Consulting

Results 1 to 3 of 3

Thread: Sleeper: Amend HTML file

  1. #1
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Sleeper: Amend HTML file

    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)

  2. #2
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Is component HTML not just text like HTML?
    Cheers,

    dr

    "Questions, help and advice for free, small projects by donation. large projects by quote"

    http:\\www.ExcelVBA.joellerabu.com

  3. #3
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •