Thank you for contacting JustAnswer.
I am sorry to hear about the problems you are experiencing. I am sorry to tell you that you cannot stop your husband from leaving. It sounds as if your husband may be avoiding facing his feelings and the issues in the marriage by having an affair. The behaviors that you describe certainly suggest that he is continuing his affair. While he continues to "self medicate" in this way it will not be possible for the two of you to repair the marriage. The only hope for the marriage is if he decides to stop the affairs and focus on his issues and the marriage.
Until or if he decides to work on the marriage, it is time for you to work on you by building up your self esteem, perhaps through some individual therapy, so that you begin to see that you do not deserve to be treated so disrespectfully XXXXX XXXXX you deserve better than this. You deserve someone who will spend some time with you, listen to you and treat you respectfully. If you think of a marriage like a bank account where when you do fun things together, are nice to each other etc. it is like making deposits in the bank and when you have stressors, fights and negative interactions it is like making withdrawals, it sounds as if your marital "bank account" is in the red. Without deposits, and perhaps the help of marital therapy, it will be difficult to have any reserve to use when you have difficulties. Since you can't change your husband, one of the things you may be able to work on is you. Consider working on taking care of you just like you might care for your children, focus on healthy activities such as exercise, eating healthy, hobbies, time with supportive people, etc. Above all, make sure you give yourself unconditional love. I wish you the best with this difficult issue. Please let me know if I can help further.