Sorry to take so long to reply, different time zones meant I was fast asleep
when you posted :-).
The code should go into a standard code module (Alt-F11, Insert>Module).
To know which workbook or whatever to add it to would require more detail on
how you will work with all of this, there are many options.