And it's very rare to use the Attack action or Full Attack action with a ranged spell anyway - you'd normally use the Cast a Spell action.
Now, that's not to say that you can't use Combat Expertise if you're taking the Attack action with a ranged weapon... as long as you're doing it in melee.
According to the Combat chapter, two creatures are engaged in melee if they are enemies of each other and either threatens the other.
If I have a longbow, and I'm five feet away from an orc with a falchion, then a/ we are enemies of each other, and b/ either threatens the other (he threatens me), so we are engaged in melee.
Thus, if I take the Attack action or Full Attack action, even though I'm making an attack with a ranged weapon (which will provoke an AoO), I am taking that action in melee, and thus qualify for using Combat Expertise.
If I cast Scorching Ray, however, I am not taking the Attack action in melee, I am taking the Cast a Spell action in melee, and thus do not qualify for using Combat Expertise.
-Hyp.