Home › Forums › General XMetaL Discussion › I can’t get this macro to replace the text in an element › Reply To: I can’t get this macro to replace the text in an element
Reply to: I can’t get this macro to replace the text in an elementFebruary 28, 2012 at 8:14 pm
Standard JScript string functions and a loop will give you that.
Insert this after rng.SelectContainerContents();
var oldtxt = rng.Text;
var newtxt = "";
Then replace the current TypeText with this:
Note that the above assumes the element does not contain anything other than text (ie: no child elements). To handle that case would require quite a bit more logic, and probably different logic using DOM or something else would make things easier to write (for me) but harder to understand.
If you use change tracking at your company and the element might contain a change tracking PI then you might use rng.TextWithRM instead of rng.Text.