When I open a spreadsheet, I want to create a macro dynamically and then execute it. The code doesn't need to be saved.

How can I do this?