Valacyclovir (Valtrex) works by preventing an important protein that's used to make genetic material from working in the herpes simplex virus and varicella zoster virus. By doing this, the medication prevents the virus from making copies of itself and spreading.