VbaProjectPart generates `vbaProject.bin` file with incorrect file extension
See original GitHub issueDescribe the bug
We are generating macro files using OpenXML SDK and when we add the VbaProjectPart to the document, we expect it to create a file named vbaProject.bin in the same way the Microsoft Office applications do.
OpenXML SDK will generate a vbaProject.xml file. Such VBA macro is functioning normally in Office applications.
Screenshots


To Reproduce
var vbaProjectPath = @"C:\dev\project\bin\vbaProject.bin";
var macroTemplate = PresentationDocument.CreateFromTemplate("MacroTemplate.potm");
var mainDoc = macroTemplate.PresentationPart;
if (mainDoc != null)
{
var vbaProject = mainDoc.AddNewPart<VbaProjectPart>();
using var reader = File.OpenRead(vbaProjectPath);
vbaProject.FeedData(reader);
reader.Close();
}
Sample repository: https://github.com/NetOfficeFw/vbamc/blob/macro/src/vbamc/VbaCompiler.cs#L101
Observed behavior
Adding the VbaProjectPart into any of these document types: WordprocessingDocument, SpreadsheetDocument or PresentationDocument will create a respective vbaProject.xml file.
The added VBA project is functional in Office applications despite having incorrect extension.
Expected behavior
The default extension for the VbaProjectPart should be .bin instead of .xml to make the filenames in line with Microsoft Office application behavior.
Desktop:
- OS: Windows 10
- Office version 365 build 2211
- .NET Target: .NET 6
- DocumentFormat.OpenXml Version: 2.16.0 and newer
Additional context
The VbaProjectPart part is defined here: https://github.com/OfficeDev/Open-XML-SDK/blob/main/test/DocumentFormat.OpenXml.Packaging.Tests/data/PartConstraintData.json
{
"Name": "DocumentFormat.OpenXml.Packaging.VbaProjectPart",
"ContentType": "application/vnd.ms-office.vbaProject",
"IsContentTypeFixed": true,
"RelationshipType": "http://schemas.microsoft.com/office/2006/relationships/vbaProject",
"TargetFileExtension": ".xml",
"TargetName": "vbaProject",
"TargetPath": ".",
"Parts": [
{
"RelationshipType": "http://schemas.microsoft.com/office/2006/relationships/wordVbaData",
"PartClassName": "VbaDataPart",
"PartContentType": "application/vnd.ms-word.vbaData+xml",
"MinOccursIsNonZero": false,
"MaxOccursGreatThanOne": false,
"FileFormat": "Office2007"
}
]
}
Incorrect exention definition: https://github.com/OfficeDev/Open-XML-SDK/blob/main/test/DocumentFormat.OpenXml.Packaging.Tests/data/PartConstraintData.json#L3596
Issue Analytics
- State:
- Created 8 months ago
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
@Asbjoedt the
vbaProjectpart is actually not XML. In [MS-OFFMACRO] 2.2.1.2 you can see that thevbaProjectpart is specified in [MS-OVBA] which describes the compound file binary format ([MS-CFB]) structure of this part.Therefore, as @jozefizso mentioned, it should have a .bin extension. This was an oversight by the SDK’s code generation engine earlier in the history of the project.
HI @jozefizso
Thank you for reporting this issue to us. I will bring this issue up during our next triage.
Hung-Chun Yu Microsoft Open Specifications Support