View Single Post
 
Old 04-25-2014, 12:56 PM
Cosmo Cosmo is offline Windows Vista Office 2007
Competent Performer
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default Looking for best way to remove VBA and CustomUI from a file via VBA

I have a document which contains a CustomUI ribbon and VBA modules to allow a user to customize the content and saves a copy of the document for each customer. I need to remove the CustomUI and the VBA components (Modules and UserForms) from the finalized document, but I have not found a reliable method to do so yet.

I tried applying the 'Normal.docm' template to the finalized document, but that seemed to work at first, but doesn't seem to be working anymore (i.e. the CustomUI is still used, and the VBA modules are still intact in the copy). I'm not sure if the file format I am saving the document may affect this or not, I am saving it as wdFormatXMLDocument.

I also tried looping through the document.VBProject.VBComponents to remove them, but this requires the 'Trust access to the VBA project object model' to be checked, and I cannot be sure that the user will have this option selected.

I tried saving the document in wdFormatXMLDocument (.docx format removes the VBA modules), then closing and reopening the document and saving as wdFormatDocument (.doc format removes the CustomUI), which worked fine on my computer (aside from changing the format of some of the bulleted text), but then the client was getting the 'Word cannot start the converter mswrd632.wpc' error when saving as .doc files.

Is there a more reliable way to remove these parts of the document via VBA?
Reply With Quote