FPHTMLWebPartElement Object
Represents a Web part in an HTML document. See also the IHTMLWebPartElement object.
This object is supported only by Web pages or sites that are based on Microsoft Windows SharePoint Services.
Using the FPHTMLWebPartElement Object
Use the webParts property of the FPHTMLDocument object to return an IHTMLElementCollection collection that represents a collection of all the Web Parts within a document. Use the Item method to return an FPHTMLWebPartElement 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 FPHTMLWebPartElement
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