Creates HTML file using template found in a column.
Have lines of HTML in a column with placeholders of where to put title, body and footer of HTML page, then call the function to create HTML page.
Passing the full file path of HTML file, title, body and footer (not HTML head and body because those are expected to be in the column as HTML lines).
Lines should have placeholders "{{$PageTitle$}}", "{{$PageContent$}}", "{{$PageFooter$}}" to replace with passing arguments of the function.
Code expects to have ShD sheet with column GA having line numbers, GB having HTML lines.

Needs VBInstr()

What is this?



Original Work

Sub SaveAsHTML_Template(Export2HTML, ExportTitle, ExportBlock, ExportFooter)
    ' saves HTML block into html file using a template
    '    Export2HTML is full html file path and name
    ' reads HTML template from D!GA:GB, GA has line no to read, GB has individual lines to be written in html
    '    accepts variables in these html lines in GB
    '        so far ...
    '            {{$PageTitle$}}
    '            {{$PageContent$}}
    '            {{$PageFooter$}}
    '    Needs VBInstr
    HTML00 = "GA1"
    PageTitleTemplate = "{{$PageTitle$}}"
    PageContentTemplate = "{{$PageContent$}}"
    PageFooterTemplate = "{{$PageFooter$}}"
    Open Export2HTML For Output As #22
    X1 = 1
    Xid = ShD.Range(HTML00).Offset(X1).Value
    Do Until Xid = ""
        Lin = ShD.Range(HTML00).Offset(X1, 1).Value
        Lin2 = Lin
        If VBInstr(PageTitleTemplate, Lin) > 0 Then
            Lin2 = Replace(Lin, PageTitleTemplate, ExportTitle)
        End If
        If VBInstr(PageContentTemplate, Lin) > 0 Then
            Lin2 = Replace(Lin, PageContentTemplate, ExportBlock)
        End If
        If VBInstr(PageFooterTemplate, Lin) > 0 Then
            Lin2 = Replace(Lin, PageFooterTemplate, ExportFooter)
        End If
        Print #22, Lin2
        X1 = X1 + 1
        Xid = ShD.Range(HTML00).Offset(X1).Value
End Sub

Export2HTML, ExportTitle, ExportBlock, ExportFooter

Views 82

Downloads 37