Is there any way a character can make an attack of opportunity using a ranged weapon?
If so, how?
What book does it come from?
Spell Compendium pg. 15-16, Ranger 1st, Sor/Wiz 1st.
Cast as an immediate action and lasting for 1 minute/level, which is excellent. It also allows you to shoot a ranged weapon while in melee without provoking. However, attacks of opportunity with ranged weapons are limited to your usual melee reach even with this spell.
I know of no spell that allows you to make attacks of opportunity at the a larger range with a ranged weapon.
Yes, there is a way to way to make attacks of opportunity (AoOs from now on) using a ranged weapon. In fact, there are several, which I'm going to detail.
Use a throwing weapon
Any throwing weapon can be used in melee with no penalty. This is the trivial solution.
Attacks of Opportunity while wielding a ranged weapon
There are several ways to have a melee weapon ready for dealing AoOs even while you're using a two-handed projectile weapon.
The first one is being able to use a weapon with a different part of your body, including but not limited to:
When you wield a two handed weapon, including a bow, you can change your grip to just hold it in your off-hand as a free action, allowing you to attack with your free hand:
Attacks of Opportunity made with a ranged weapon
Some bows from Races of the Wild are built to double as melee weapons:
Some ways to do a ranged AoO:
These options are not guaranteed to prevent people at the right distance to make an AoO against your using a ranged weapon in melee.