From the VBA editor (ALT+F11 will open it) Insert > Module. Paste the code into that module. - Although aimed at Word the process described at
http://www.gmayor.com/installing_macro.htm is almost identical and may help.
As for creating a rule -
https://support.office.com/en-za/art...7-a50704d66c59
One of the options is run a Script and the script you want to run is AddTag, which will almost certainly be the only script listed to select. Set conditions to identify the particular messages or it will tag all incoming messages.
You can run the 'test' macro with a received message selected to test how it works.