Excommunication of laypeople principally means that they are cut off from receiving the sacraments. It does not mean that the Church is condemning a person to hell. In fact, excommunication is intended to be a medicine to inspire people to repent and be reconciled to the Church. Once reconciled to the Church, that person may again receive the sacraments.
If an excommunicated person dies without being formally reconciled to the Church, he can be saved if he truly and sincerely repents all of his mortal sins before death. Certainly we may pray that a person in these circumstances be interiorly reconciled to God and the Church through full repentance before death.