Magnets can easily be attached to many things using Heat Shrink Tubing. The tubing, designed to insulate electric connections, can be found in most hardware stores in the electric supply area.
This might seem like an obvious solution. Actually, it took a couple of years to come up with this after seeing velcro fail at holding pens in place at my daughter's pre-school. I tried Sugru and that wasn't working that great. This solution proved easy and looks clean. Too often it takes a long time to discover the obvious.
*Thanks for all the comments!
Step 1: Just Insert Tubing, Add Magnet and Heat With a Flame.
You can also use steam from a kettle (although it doesn't make the tubing shrink quite as much), or a heat gun, etc.
If one magnet doesn't hold well enough, you can add an additional one or two end-to-end to increase the holding force.