DivID Property Example

This example saves a range of cells to a Web page, and then it obtains the identifier from the <DIV> tag of this item and finds the line on the saved Web page (q198.htm). The example also creates a copy of the Web page (newq1.htm) and inserts a comment line before the <DIV> tag in the copy of the file.

Set objPO = ActiveWorkbook.PublishObjects.Add( _
    SourceType:=xlSourceRange, _
    Filename:="\\Server1\Reports\q198.htm", _
    Sheet:="Sheet1", _
    Source:="C2:D6", _
    HtmlType:=xlHtmlCalc)
objPO.Publish
strTargetDivID = objPO.DivID
Open "\\Server1\Reports\q198.htm" For Input As #1
Open "\\Server1\Reports\newq1.htm" For Output As #2
While Not EOF(1)
    Line Input #1, strFileLine
    If InStr(strFileLine, strTargetDivID) > 0 And _
        InStr(strFileLine, "<div") > 0 Then
            Print #2, "<!--Saved item-->"
    End If
    Print #2, strFileLine
Wend
Close #2
Close #1