You can’t be excommunicated from the Church if you have never belonged to it. If you do belong to the Church, you can be excommunicated for various offenses, but any excommunication can be lifted by the proper authority. Some excommunications can be lifted by the priest, some by the local bishop, and some by the Pope. But they can all be lifted. In the case of danger of death, any priest, even a laicized priest, can lift an excommunication and forgive any sin. When an excommunication is lifted, the person again belongs to the Church.
For an excommunication to automatically apply the following conditions are necessary:
The person must know with moral certainty that the action he is about to take will result in an automatic excommunication. If he believes it to be simply wrong, but not something that would automatically excommunicate him, then he is simply guilty of a sin which can be forgiven in Confession, but he is not excommunicated.
If he wrongly believes that the action would result in his excommunication, but does it anyway, he still is not excommunicated, although he is guilty of a mortal sin.
Some examples of offenses that incur an automatic excommunication, notwithstanding #1, above, are abortion, or casting the Holy Eucharist on the ground or discarding it in the sacrarium (the sink in the church sacristy that drains directly into the ground), or any intentional desecration of the Eucharist, or attacking a priest, religious brother, or nun.
All clergy and Extraordinary Ministers of Holy Communion should be aware of that second one, because I’ve heard several EMHCs say that they do this. They are not aware that they should not be doing it! So in their case, being unaware of the penalty for doing so, it does not apply to them. Nevertheless, they should be instructed that they must not do that, and that if they knowingly ignore this law, then they are automatically excommunicated.
The reason the Church has imposed these penalties on certain actions is to educate the faithful about the seriousness of the offense. It’s one thing to tell EHMCs not to pour extra Precious Blood into the sacrarium. It’s a whole other thing to tell them that if they do so they will be automatically excommunicated. It adds a whole level of gravity to the law that gets the point across.