I am sorry to bother again. Actually, i made the whole thing to work properly now.
However i ran into a new problem: I modified the macro to make it possible to handle several selections. The problem is, that when i restore the selection, ThisComponent.CurrentController.select(oRange) in your example, I can only restore one selection. I have tried for some hours now to make it possible to restore a multi-selection, but I failed constantly. Let's say that I highlight three parts in a text, by clicking and dragging while the Ctrl key is held. Then the macro can handle each one of them, that's no problem. I get my text replaced and everything is OK, until the end of the macro. So what do I want to happen at the end? Well, I want to restore the selections. Not just one of them, ALL of them. Just to make it possible to run the same macro again on the same selections. I use some global variables to "record" what the macro did last time, and next time I run it I want it to do something else to the same text. Well, if you really want to know, I am trying to make my own Uppercase-Lowercase conversion, to use instead of the built in Change Case function. I am also doing it to learn about macros. So I assigned the macro to Shift+F3. My thought is that first time I hit Shift+F3, all selected characters are converted to Uppercase. Second time the macro is run, it will convert to lowercase (if the selection didn't change since last time). Third time, it will convert to Sentence case (first letter after ". " (point + space) and after ": " will be Uppercase, other characters won't change). Fourth time, it's Title Case. Fifth time it toggles from the ORIGINAL case (which therefore has to be remembered the first time the macro runs on a specific selection/multi selection). Sixth time it toggles back again to its original state. Seventh time is the same as first time and so on. So, that's why the multi selection needs to stay there after the macro finished. At the moment I just can not figure out (maybe because I am really stupid) how to do this. Everything else is working and it works as long as I don't do multi selections. Johnny Andersson
