I didn't have time to check the thousands of pages in the OpenXML SDK documentation but you could try something like this:
The .xlsm
file is a ZIP archive containing mostly XML files. You need to remove the references to macros from the workbook.xml.rels
file in the xl\_rels
folder. Here is a sample:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Target="worksheets/sheet3.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId3"/>
<Relationship Target="worksheets/sheet2.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId2"/>
<Relationship Target="worksheets/sheet1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId1"/>
<Relationship Target="vbaProject.bin" Type="http://schemas.microsoft.com/office/2006/relationships/vbaProject" Id="rId6"/>
<Relationship Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Id="rId5"/>
<Relationship Target="theme/theme1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Id="rId4"/>
</Relationships>
It is the relationship of type http://schemas.microsoft.com/office/2006/relationships/vbaProject
you need to remove. The file referenced in the relationship should also be removed from the ZIP archive. In this case the file is named vbaProject.bin
and is placed in the xl
folder.
Using the OpenXML SDK you should be able to navigate the logical structure of the Excel file and perform this kind of cleanup without understanding the exact structure of the ZIP archive. However, inspecting the Excel file as if it was a ZIP archive can still be helpful to understand the structure of the file.