Except for the case of heart attack associated VSD, this condition is always present at birth.
Drinking alcohol and using the antiseizure medicines depakote and dilantin during pregnancy have been associated with increased incidence of VSDs. Other than avoiding these two things during pregnancy, there is no known way to prevent a VSD.
Zipes DP, Libby P, Bonow RO, Braunwald E, eds. Braunwald's Heart Disease: A Textbook of Cardiovascular Medicine, 8th ed. St. Louis, Mo; WB Saunders; 2007.