Scientists don't believe vitamin D can affect anxiety in a direct way. But it's believed that the two have indirect relations.
In the past, our ancestors believed that sun meant crops could grow. They could have enough food. But the absence of sun meant little food, a grim prospect. So over the long evolution, humans may have developed a love for sun. As you know, sunshine helps the formation of vitamin D in the body. This may explain why vitamin D makes people feel better.
Exercises can help control anxiety. They usually take place outdoors. So those who fail to stay active spend more time indoors, thus having lower vitamin D levels.
Keyword: vitamin d anxiety