BMW E46 Sealed key battery replacement.("Diamond shaped key")
BMW will tell you the batteries cannot be replaced and instead you have to buy a new key for around £100, but with patience and some careful work you can change the rechargeable battery.
Warning. This should only be tried if it's your spare key that is not working, you have nothing to lose (apart from a £6 battery). I would not advise you to do it if you only have one key (as you may not be able to use the key at all if you make a mistake).
Using a suitable thin bladed knife(Stanley knife, model knife/craft knife) carefully cut along and around the seam of the key(DO NOT GO IN TOO DEEP AND DAMAGE THE INSIDES!), you should find it easier to start at the top where the keyring "loop" is.
Now using some pliers or a small prying instrument break the small spot welds on the battery that connect it to the circuit board and remove the battery.
The battery needed to replace your old one is a Panasonic VL20203v. Link here. Panasonic VL2020-1HFE Rechargeable Coin Cell Tagged Battery - Cell Pack Solutions
Solder the new one in(remember to put the positive and negative the right way round) and make sure everything fits back together. Before glueing the key, tightly band the key back together and test it first.
Key glued back together.
Put the working key in the ignition. Turn to position 2 for 1 second then back and remove the key.
Press and hold the "unlock" button then press the "lock" button 3 times, you should hear all the locks cycle through.
Now take the non working key and press and hold the "unlock" button then press the "lock" button 3 times.
Then turn the ignition on and off again to end the programming.
This DIY is not guaranteed to work if your fob is faulty, a replacement battery will not solve this.
If it is your battery that is the problem and you do the work correctly it will work.