I spent the whole night setting that up.
From what I'v read other coders have spent days without finding a pallatable solution.
It was one of the thoughest coding challenge I'v met.
Everything seemed to be done to make it impossible.
Everything I found was stubbornly putting the caret at the end of the textarea, did nothing, were extremely complicated or gave an error.
I think I have found a solution with this:
Quiet brutal, I know but it works.
look here or here:
Set objTA = document.getElementById(TextAreaId)
objTA.focus
MyTag = "!*g$" '---It can be whatever you want, but something unusual
document.selection.createRange().text = MyTag
'---We replace temporarily VbCrlf par Vblf so that 1 new line = 1 character and not 2 ---
strTemp = Replace(objTA.innerText, VbCrlf, Vblf)
CaretPos = InStr(strTemp, MyTag)-1
'---This line can be obmitted if you change the text or the HTML of the textarea before restoring the caret---
objTA.innerText = Replace(Replace(strTemp, MyTag, ""), Vblf, VbCrlf)
'--- Add your code here
'--- Restore the position of the caret---
Set range = objTA.createTextRange()
range.collapse true
range.moveStart "character", CaretPos
range.moveEnd "character", 0
range.select