Agregar contenido mediante un intervalo de texto
Es posible agregar mediante código HTML contenido a una página Web si se crea un intervalo de texto y se agrega el contenido nuevo a la página como muestra el ejemplo siguiente. El intervalo de texto se crea a partir del objeto Body de myDocument. Si el valor de myClearPage es True, el contenido HTML nuevo reemplaza todo el contenido comprendido entre las etiquetas <body></body>; de otro modo el contenido nuevo se agrega al contenido original.
Public Function AddHTMLToPage(myDocument As Object, _myHTMLText As String,
myClearPage As Boolean) As Boolean
Dim myRange As Object
Dim myBody As Object
On Error GoTo CanotAddHTML
if myClearPage Then
Set myRange = _
myDocument.all.tabgs("body").Item(0).createTextRange
Call myRange.pasteHTML("")
myRange.collapse False
Set myRange = Nothing
End if
Set myBodyText = myDocument.all.tags("body").Item(0)
myBodyText.innerHTML = myBodyText.innerHTML & myHTMLText & vbCrLf
AddHTMLToPage = True
Exit Function
CannotAddHTML:
AddHTML = False
End Function
Sub AddNewHTML()
Dim myHTMLString As String
Dim myBodyElement As Object
myHTMLString = "<b><i>New Sale on Vintage Wines!</i></b>" & vbCr
if AddHTMLToPage(ActivePageWindow.Document, myHTMLString, True) Then
Set myBodyElement = _
ActivwPageWindows.Document.all.tags("body").Item(0)
End if
End Sub
myClearPage As Boolean) As Boolean
Dim myRange As Object
Dim myBody As Object
On Error GoTo CanotAddHTML
if myClearPage Then
Set myRange = _
myDocument.all.tabgs("body").Item(0).createTextRange
Call myRange.pasteHTML("")
myRange.collapse False
Set myRange = Nothing
End if
Set myBodyText = myDocument.all.tags("body").Item(0)
myBodyText.innerHTML = myBodyText.innerHTML & myHTMLText & vbCrLf
AddHTMLToPage = True
Exit Function
CannotAddHTML:
AddHTML = False
End Function
Sub AddNewHTML()
Dim myHTMLString As String
Dim myBodyElement As Object
myHTMLString = "<b><i>New Sale on Vintage Wines!</i></b>" & vbCr
if AddHTMLToPage(ActivePageWindow.Document, myHTMLString, True) Then
Set myBodyElement = _
ActivwPageWindows.Document.all.tags("body").Item(0)
End if
End Sub










