question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VbaProjectPart generates `vbaProject.bin` file with incorrect file extension

See original GitHub issue

Describe 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

image

image

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:open
  • Created 8 months ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tomjebocommented, Jan 13, 2023

@Asbjoedt the vbaProject part is actually not XML. In [MS-OFFMACRO] 2.2.1.2 you can see that the vbaProject part 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.

1reaction
hunyucommented, Jan 7, 2023

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

xl/vbaProject.bin part. (Visual Basic for Applications (VBA)) ...
This issue can be caused when you open a xlsm-file, with "wrong" language settings and there are "foreign" characters (like: æ, å, ä,...
Read more >
Recovering the vbaProject.bin
Rename the file extension to .xls; On the developer tab disable all macros; With excel closed Hold Ctrl, double-click to open the bad...
Read more >
Read VBA macros (or vbaProject.bin) of an Excel file ...
One difficulty is to find and parse the VBA macros of an Excel file. We know that an Excel file can be converted...
Read more >
excel/vba project corrupt! | MrExcel Message Board
Go into "CorrXL.zip" and find "VBAProject.bin". Right-click and Copy. Go into "Doc1.zip" and find "VBAProject.bin". Delete this one and paste ...
Read more >
Remove Excel VBA password - jaytaala.com Confluence
Hi, I've just used this method on an .xlsm file and it worked the second time. The first time I made the mistake...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found