June CTP Drop: RemoveCustomization method
Another thing that came back loud and clear in developer feedback is that there needs to be a way to cleanly remove the VSTO 2005 customization from a Word or Excel document. We have provided such a method called RemoveCustomization() that you will find on the Microsoft.Office.Tools.Excel.Workbook object and the Microsoft.Office.Tools.Word.Document object. RemoveCustomization strips the VSTO customization out of the document (doc properties, embedded hidden ActiveX control) and effectively "uncustomizes" the document. It also (in RTM) detaches the ActionsPane. It does not remove any managed controls from the document--you will have to do this yourself.
A scenario where RemoveCustomization is useful goes like this.
A consultant has a Word template that runs code whenever she opens it that shows a wizard that is filled out that then populates the document with all sorts of interesting stuff. The consultant then wants to send the generated document to a client--but without any code associated with it. The code that shows the wizard can be written in such a way that it removes the customization after it runs: e.g.
Private Sub ThisDocument_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
' Show fancy wizard that
' fills in the word document
Dim f As New FancyWizard
f.ShowDialog()
' Now that the document is filled in, remove the customization
' so this can be sent to people without code in it.
Me.RemoveCustomization()
End Sub