You shouldn't order them to "attach archers"

, as this will make the charge them to kill them in melee.

Better order them to "fire at: archers". They will switch to another target ( : nearest) as soon as there is no more valid pre-set target, e.g. no archers, or all enemy archers routing.