A VPN can absolutely protect you from hostile software elsewhere on the network, so long as you don't accept traffic from any source other than the VPN. Doing that correctly is a fairly sophisticated thing to do though, and a sufficiently sophisticated threat might find a way to attack you still.
It all depends on your own technical ability and whether you're protecting yourself from a script kiddie or palantir.