Adding text from VBA macro to an HTML document

G

ggivati

Hi,

I am trying to create a macro that will add a custom XML tag to an HTML document. the tag looks like this:
"<GEN:FieldValue Name="myName" />

When I tried using pasteHTML I get an error and I believe its because this is not a standard HTML phrase, so I am trying to use insertAdjacentText instead. this causes me two problems:

The first one is that it works every second time in an object saying that the object variable is not set. When I try to run it the second time it works but then it replaces every <,> and " with their HTML translations, i.e. < etc.

The code I'm using is as follows:


Sub AddHTML()

'Set up variables
Dim myTextRange As IHTMLTxtRange
Dim myHTML As String
Dim myDoc As FPHTMLDocument
Dim currentElement As IHTMLElement

Set myDoc = Application.ActiveDocument
If myDoc.ViewMode = 2 Then
myDoc.parseCodeChanges
End If

Set currentElement = myDoc.activeElement

currentElement.insertAdjacentText "afterBegin", "<GEN:FieldValue Name=""gil"" />"

End Sub

Any suggestions ?

Gil
 
Top