Can my ranged unit melee attack if I want it to?
No, you cannot force ranged units to perform a melee attack (but they can range-attack a unit in the adjacent hex), and this includes melee attacking to capture a city - so always bring some melee units to a siege.
They can be engaged in melee if an enemy attacks them with a melee unit, but this uses the ranged unit's strength value, instead of ranged strength, which is usually much lower - expect them to lose against unit of a similar technological level; it's best to keep them out of melee range.
The exceptions are the Gatling Gun and Machine Gun units introduced by Gods & Kings, they are explicitly designed for getting up close and personal - having only a single tile of range and matching strength and ranged strength scores that compare to the melee units of their time.
The same applies for all updated version of the archer, all updated version of the catapult, and all ranged combat ships/submarines - any 'bombarding' ranged unit of any type, essentially.
(Note: the Gods and Kings expansion divides ships in to melee and ranged, performing the same functions as their land equivalents, so this distinction is now important at sea too, especially since the melee naval units can capture now cities).
All these units can, I believe, capture civilians by entering the tile they are on - and, in the case of ships, they can destroy any embarked unit with the same method (Note: this has changed in the Gods and Kings expansion; embarked units can defend themselves and are not automatically destroyed). This always counts as the unit performing an attack, so they lose that attack until the next turn.
I'm not sure, but it's definitely possible sometimes with a scout that have been upgraded to an archer/crossbowman by discovering ruins. (These are better than normal archers in that they can move much faster through rough terrain.)
I just got "robbed unfairly in a most dastardly way":
- I was using a scout/archer to use range attacks, by right-clicking as per normal.
- The scout/archer was within 2 hexes of an enemy city.
- There was a hill in the way so he didn't have line of sight.
- I didn't realise this because I had a longswordsman standing on top of it, making it look like a normal flat plain.
- I right-clicked the enemy city to use the archers ranged attack on it.
- The archer didn't employ his trusty bow and arrows. Oh no.
- Instead he ran round the hill and used a lame melee attack on the city and died.
I think he used the melee attack, because the ranged attack wasn't available, which in turn was entirely the hill's fault.