With the sunroof closed, remove the switch and see if it still cycles open/close with the switch removed and you turn the ignition on/off.
If it stays closed, BINGO! Switch problem.
I would be shocked, if it wasn't a bad switch. But that is still a possibility...