In the Bentley manual for the E32 is a good description, should be similar on the E31.
As far as I remember:
remove the motor, the close the sunroof completely with the tool in the tool box.
Then use the switch to open and then to close. Now it has the exact points registered. Then install the motor again. Fenito.