IHTMLWebPartElement Object

Microsoft FrontPage Visual Basic

IHTMLWebPartElement Object

IHTMLWebPartElement

Represents a Web part embedded in an HTML document. The IHTMLWebPartElement object provides access to a limited number of properties and methods related to the embedded Web parts. For access to all properties and methods, use the FPHTMLWebPartElement object.

This object is supported only by Web pages or sites that are based on Microsoft Windows SharePoint Services.

Using the IHTMLWebPartElement object

Use the webParts property of the IFPDocument object to return an IHTMLElementCollection collection that represents a collection of all the embedded Web parts within a document. Use the Item method to return an IHTMLWebPartElement object that accesses a specific Web part, referenced by ordinal number. The following example accesses the first Web part in the active document.

    Dim objPart As IHTMLWebPartElement

Set objPart = ActiveDocument.webParts.Item(0)
  

Use the InsertAdjacentHTML method, as shown in the following example, to insert a Web Part into a document.

    Public Sub InsertWebPart()

    Dim strPageDirective As String
    Dim strRegisterDirective As String
    Dim strWebPart As String
    Dim objWebPart As FPHTMLWebPartElement

    strPageDirective = "<%@ Page Language=""C#"" Debug=""true""%>"

    strRegisterDirective = "<%@ Register TagPrefix=""WebPartPages"" " & _
        "Namespace=""Microsoft.SharePoint.WebPartPages"" " & _
        "Assembly=""Microsoft.SharePoint, Version=11.0.0.0, " & _
        "Culture=neutral, PublicKeyToken=71e9bce111e9429c""%>"

    ActiveDocument.DocumentHTML = strPageDirective & vbCrLf & _
        strRegisterDirective & vbCrLf & ActiveDocument.DocumentHTML

    strWebPart = "<form runat=""server"">" & vbCrLf & _
        "<WebPartPages:ImageWebPart webpart=""true"" " & _
        "runat=""server"" id=""insertedwebpart"">" & vbCrLf & _
        "</WebPartPages:ImageWebPart>" & vbCrLf & "</form>"

    ActiveDocument.body.insertAdjacentHTML "afterBegin", strWebPart
    Set objWebPart = ActiveDocument.webParts.Item("insertedwebpart")

End Sub