Q:

How to insert element into DOM at current (cursor) position

I wanted to insert SpanElement into current (cursor) position of DOM.
I use this VB6 function:
Private Function InsertSpan(Tipo As String, Nome As String)

Dim oSpan As MSHTML.HTMLSpanElement
Dim oCurElement As MSHTML.IHTMLElement
Dim oDOM As MSHTML.HTMLDocument

Set oDOM = HTMLEdit.DOM
Set oCurElement = oDOM.activeElement

Set oSpan = oDOM.createElement("SPAN")

oSpan.Id = Tipo & "." & Nome
oSpan.className = Tipo
oSpan.innerHTML = "<b><font size='3' color='#000000'></font></b>"
oSpan.lastChild.lastChild.innerText = "[" & Nome & "]"
oSpan.Style.backgroundColor = "yellow"

oSpan.hideFocus = True
oSpan.contentEditable = "false"
oSpan.Style.verticalAlign = "middle"

oCurElement.appendChild oSpan
oDOM.parentWindow.Focus

End Function

but SpanElement is appended to the current element.
Thanks, Luigi.

A:

I solved it replacing 
oCurElement.appendChild oSpan

with
Dim objRange As IHTMLTxtRange
Set objRange = oDOM.selection.createRange
objRange.pasteHTML oSpan.outerHTML

Thanks to all!

