Can I edit a macro through a macro?

Yes. @DanThomas has done this in a number of his macros.

Here are two in particular you might look at:

You will need to be very conversant with JavaScript.

Good luck, and let us know how it goes.