Can ranged shooting be conducted by any friendly eligible unit at an enemy unit adjacent to another friendly unit whether a melee combat has been declared or not? I.e. ranged combat by one or more units on an enemy unit adjacent to a different friendly unit, enemy unit survives and does not retreat, then melee can be carried out against the enemy unit.
A unit adjacent to an enemy unit is considered “in melee”. Nothing has to be declared. Also remember that a unit which is adjacent to an enemy unit cannot engage in ranged shooting. If said ordered unit wants to ‘battle’; it must be melee with the adjacent enemy unit.
Yes, a unit can attack with ranged fire against an enemy unit, even if a friendly unit is adjacent to that enemy - as long as line of sight is available. As the attacker you get to choose which unit attacks first. With ranged fire the enemy does not have the opportunity to battle back, but XSW rolls do not hit (unless if ART unit in combined arms attack). In melee the attacking unit hits on XSW and also might get an extra die (e.g., French line infantry attacking an enemy infantry unit).
If the ranged fire results in the enemy retreating, (flag rolls) then the other friendly unit may only get ranged fire or maybe not any combat at all if the enemy unit retreats out of range.
So you have to look at the odds and make a decision. If the enemy unit only has 1 or 2 blocks it may be better to attack in melee first to get a better chance to eliminate the unit and also perhaps to take ground.