You could theoretically write code to write code, but you will probably run
into problems quickly (virus detection may think it's a virus and
quarantines the workbook. The code persists, so it needs to be cleaned up
and rebuilt. The macro is reformed as a string, making edits a pain).
John Walkenbach has a nifty macro to do this using a class, avoiding the
problems above.
http://www.j-walk.com/ss/excel/tips/tip44.htm
To delve into this more, if you have access to it, check out Francesco
Balena's Programming Visual Basic 6. Balena's one of the best authors out
there and he has a chapter in his book devoted dynamically created forms and
events.