I am not a teacher, but I am a native speaker.
It could also be said "When the dog barks, the baby wakes up". Does that make more sense? It could also be said "If the dog happens to bark, the baby will wake up".
Also, do not depend on MS Word's grammar-checker. English sentence structure is much too complex for a mindless computer to correct it I always turn grammar check off first.
Student or Learner