The easiest way to make any macro is to simply manually do the desired edit operation why you have UE in "record" mode. UE will write macro code for every keystroke (and most mouse clicks) you do. When your done. you stop the record.
you now have working macro code. you can either use it as is or use it as a basis for futher editing. I did such a record.
I started with some text highlighted and then put UE in record mode.
I then did a cut, put in the begin tag, pasted and then typed in the end tag. I then stopped the record. I edited the recorded macro and put an if statement around all of it saying on do this if there is a range highlighted.
Once you have the macro code you can give it a name, and even map it to your desired keyboard shortcut.
here is that code...