You can't get there from here.
The .40 uses a full length guide rod, a slightly larger frame, to accomodate a slightly more powerful round.
The mags would fit, but the extractor and headspace of a 9mm gun would wouldn't work with a .40 round.
(Bad headspace can lead to the gun blowing up in your hand.)
As Raro suggests, the .40 barrel would be too large (in diameter) to fit in the 9mm slide, and the barrel might not lockup or even allow the slide to close properly, etc., etc.
The reverse CAN be done: get a special barrel (Bar-Sto) made in 9mm for the .40 version. Bar-STo can adjust the custom barrel so that the extractor will work and headspace is correct. This is done regularly by guys who shoot SIGS and Berettas.