Deleting macro''s from document programmaticaly
I see there is no VBAProjectPart ?
I want to programmaticaly delete the vbaProject.bin and references to it.
So essential removing the macro's from an xslm or docm file.
Is this possible, or do I just replace the vbaProject.bin with an empty one.
And don't bother in using this sdk.
Pierre,
afaik there is no VBAProjectPart, but you could use the IdPartPair class to loop though the parts of a certain hierarchy and compare the relationshiptype of the corresponding OpenXmlPart.
Manually you would have to remove the following:
/word/vbaData.xml
/word/vbaProject.bin
/word/_rels/vbaProject.bin.rels
entry: <Relationship Id="rIdx" Type=http://schemas.microsoft.com/office/2006/relationships/vbaProject
Target="vbaProject.bin"/> from /word/_rels/document.xml.rels
entry: <Override PartName="/word/vbaData.xml" ContentType="application/vnd.ms-word.vbaData+xml"/>
from[Content_Types].xml
You can do this with the means of the SDK:
const
string relTypeVBA = "http://schemas.microsoft.com/office/2006/relationships/vbaProject"; using
(WordprocessingDocument wDoc = WordprocessingDocument.Open(sFilePath, true)) {
MainDocumentPart mainPart = wDoc.MainDocumentPart;
foreach (IdPartPair p in mainPart.Parts)
{
if (p.OpenXmlPart.RelationshipType == relTypeVBA )
{
mainPart.DeletePart(p.RelationshipId);
break; // there is just one VBA Part
}
}
}
This leaves you with a docm and you can't just rename to docx.
Hope this helps,
Jens