Try cleaning and lubricating the tracks, and then re-teach the motor. This comes from the workshop manual:
It is necessary to re-teach the motor for the sliding roof in the event of emergency operation or replacement of parts on the sliding roof motor (seals, sliding-roof drive) or if the entire system is replaced. The data of limit positions and characteristics are stored and are retained even if the battery is disconnected.
Teaching motor for sliding roof
1. With the ignition switched on, press the Lift button and move the motor for the sliding roof to the raised limit position.
2. Press the Lift button again and keep depressed. After around 10 seconds, a complete cycle takes place from the raised limit position to the positions "lower "" open "" close". Teaching of the characteristics has been completed after this process.
Note: The Lift button must not be released during the entire process. In the event of a restart, the motor for the sliding roof must always be moved to the limit position first.
3. If the motor for the sliding roof should move back during Item 1, then the closing force limitation function has responded (motor for sliding roof was taught). The Open button must be re-taught in this case.
Teaching motor for sliding roof
1 Press the Open button until the motor for the sliding roof stops. Then release the button. Press the Open button again until the motor for the sliding roof stops again. Then release the button.
2 Press the Open button again and keep depressed. The entire process takes place after approx. 10 seconds: "close - lift - lower - open - close".