Menu selection works sometimes

I have a very simple macro in Visual Studio - all it does is select Close Solution. Sometimes it works, usually it doesn't, claiming that the menu item doesn't exist. It does, though, and I can select it manually. What's with the inconsistency?