VbaProject.Modules Is Empty Even Though There Is Code

To reproduce:

var presentation = new Presentation("PP_Acx_CheckBox_Status.pptm");
Assert.NotEmpty(presentation.VbaProject.Modules);

The expected result is for the assertion to pass.
However, the VbaProject.Modules collection is empty.

When looking inside the pptm file, inppt\vbaProject.bin, there is clear VBA code; here is the output of the olevba tool:

===============================================================================
FILE: PP_Acx_CheckBox_Status.pptm
Type: OpenXML
-------------------------------------------------------------------------------
VBA MACRO Slide1.cls
in file: ppt/vbaProject.bin - OLE stream: 'VBA/Slide1'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub CheckBox1_Click()
    Dim s As Shape: Set s = ActivePresentation.Slides(2).Shapes(1)
    s.TextFrame.TextRange.Text = "Status: " & IIf(CheckBox1.Value, "On", "Off")
End Sub
+----------+--------------------+---------------------------------------------+
|Type      |Keyword             |Description                                  |
+----------+--------------------+---------------------------------------------+
|AutoExec  |CheckBox1_Click     |Runs when the file is opened and ActiveX     |
|          |                    |objects trigger events                       |
|Suspicious|Hex Strings         |Hex-encoded strings were detected, may be    |
|          |                    |used to obfuscate strings (option --decode to|
|          |                    |see all)                                     |
+----------+--------------------+---------------------------------------------+

PP_Acx_CheckBox_Status.pptm.zip (28.7 KB)

@Buffer2018,
Thank you for contacting free support.

We checked the presentation in Microsoft PowerPoint. If you open it and go to View > Macros, the dialog also shows that there are no available macros/VBA modules.

Also, if you add a new macro manually and then open Microsoft Visual Basic for Applications, you will see only the module that was just added. The existing code detected by olevba is not shown by PowerPoint as an available VBA module.

Therefore, the behavior of Aspose.Slides is consistent with Microsoft PowerPoint in this case: presentation.VbaProject.Modules is empty because PowerPoint also does not expose any existing VBA modules for this presentation.

Please see my reproduction:
Step 1: create new macro
image.png (14.9 KB)

Step 2: Powerpoint displays the code
image.png (25.9 KB)

@Buffer2018,
Yes, but if you save the presentation with the added new_macro, presentation.VbaProject.Modules.Count will return 1, and presentation.VbaProject.Modules[0].SourceCode will return the code you added.

It looks like the presentation may be corrupted, or the “hidden” macro may have been created in a non-standard or incorrect way. Since PowerPoint itself does not display this VBA code as a regular VBA module, the current behavior of Aspose.Slides looks consistent with PowerPoint.

Could you please clarify how the “hidden” macro was created and added to the presentation?

Hello @andrey.potapov
Creating a document like this is extremely easy and built-in inside powerpoint:

  1. The Developer tab must be enabled (Options > Ribbon > Customize Ribbon)
  2. ActiveX must be enabled in the Trust Center (Options > Trust Center > ActiveX)
  3. Go to the developer tab and add a control e.g., a checkbox.
  4. Double click the checkbox → This will create a “_Click” macro for the checkbox.
  5. Write some code and save, then close the VBA editor and click on “Show macros”.

Same result: the list is empty, but if you create a new macro, the VBA editor will show the checkbox event handler.

This is not a non-standard or incorrect way to create a “hidden” macro and I think it would be beneficial if Aspose.Slides would expose this content, as it very obviously exists as a stream in the vbaProject.bin file inside the PPTM file, and the file format is fully documented.

@Buffer2018,
Thank you for the additional information. I need some time to investigate the case. I will get back to you as soon as possible.

@Buffer2018,
I have investigated the presentation and found that it contains an ActiveX control. The VBA code you pointed out belongs to this control, so it is not exposed as a regular VBA module through presentation.VbaProject.Modules.

Please try using the following code snippet:

var presentation = new Presentation("PP_Acx_CheckBox_Status.pptm");
Assert.NotEmpty(presentation.Slides[0].Controls);

This confirms that the ActiveX control can be accessed through the slide’s controls collection.