From Doctrine of Life:
18. Who does not know, or who cannot know, that evils impede the Lord’s being able to enter a person? For evil embodies hell, and the Lord embodies heaven, and hell and heaven are opposed to each other. Insofar as a person is engaged in one, therefore, so far he cannot be engaged in the other. For one acts in opposition to the other and destroys it.
19. During the time a person is in the world, he is between heaven and hell, having hell below and heaven above; and he is kept free then to turn either in the direction of hell or in the direction of heaven. If he turns in the direction of hell, he turns away from heaven. But if he turns in the direction of heaven, he turns away from hell.
In other words, during the time a person is in the world, he stands between the Lord and the devil, and he is kept free to turn either to the one or to the other. If he turns to the devil, he turns away from the Lord. But if he turns to the Lord, he turns away from the devil.
Or to put it another way, during the time a person is in the world, he is between evil and good, and he is kept free to turn either to the one or to the other. If he turns to evil, he turns away from good. But if he turns to good, he turns away from evil…
…21. It is clearly apparent from this that insofar as a person refrains from evils, so far he is in the Lord’s presence and in the Lord, and that insofar as he is in the Lord, so far he does good, not of himself, but from the Lord.
This results, then, in the general law, that insofar as someone refrains from evils, so far he does good.
22. There are, however, two requisites:
One, that the person must refrain from evils because they are sins, that is to say, because they are infernal and works of the devil, being thus against the Lord and against His Divine laws.
Second, that the person must refrain from evils as being sins as though of himself, but know and believe that he does so from the Lord…
23. From all this, three conclusions follow:
1. That if a person wills and does good before he refrains from evils as being sins, the good that he does is not good.
2. That if a person thinks and speaks piously, and does not refrain from evils as being sins, his pious thoughts and words are not pious.
3. That if a person gains much knowledge and wisdom, and does not refrain from evils as being sins, he is still not wise.