Roman Catechism 15.57

Chapter 15 — Part II: The Sacraments — Introduction on the Sacraments in General

Section 57. Unworthiness Of The Minister And Validity — Since the ministers of the Sacraments represent in the discharge of their sacred functions, not their own, but the person of Christ, be they good or bad, they validly perform and confer the Sacraments, provided they make use of the matter and form always observed in the Catholic Church according to the institution of Christ, and provided they intend to do what the Church does in their administration. Hence, unless the recipients wish to deprive themselves of so great a good and resist the Holy Ghost, nothing can prevent them from receiving (through the Sacraments) the fruit of grace.