Нашел решение:
function add_tags(str1, str2)
{
var obj=document.getElementById("memo1");
obj.focus();
if(document.selection)
{
var s = document.selection.createRange();
s.text = str1 + s.text + str2;
}else
{
var len = obj.value.length;
var start = obj.selectionStart;
var end = obj.selectionEnd;
var scrollTop = obj.scrollTop;
var scrollLeft = obj.scrollLeft;
var sel = obj.value.substring(start, end);
var rep = str1 + sel + str2;
obj.value = obj.value.substring(0,start) + rep + obj.value.substring(end,len);
obj.scrollTop = scrollTop;
obj.scrollLeft = scrollLeft;
}
}