there are multiple approaches for this problem.
First would be to change the Aquiration range of units to lower values in Object Editor or by Triggers. However the problem is that this will mess up your ranged units, because no matter how big Attack Range they have, they will always be able to attack only targets that are closer than Aquiration range.
Second approach is to check with triggers, with even Unit - Unit attacks unit and check the distance from the attacker to attacking unit, if it is under your desired value, you let him attack, if it is further than you want, you will order the unit to stop. This may mess up with unit orders a bit tho and Im not sure that it will not mess up when you "Smart" enemies(Right click them)