How to Set HyperLink.ActionType.StartMacro in Aspose.Slides for .NET 21.2?

Hi, I’m using the latest version of Aspose.Slides (21.2.0.0).

I want to add an action button in the slide that calls the macro.
But I don’t know how to set it.

var shape = ppt.Shapes.AddAutoShape(ShapeType.BlankButton, 0, 0, 300, 100);
shape.HyperlinkClick = /* How do you do it? */

I debugged and looked at the existing action buttons.

ppt.Slides[0].Shapes[0].HyperlinkClick

Please see the attached image.
scsh 2021-03-12 161924.jpg (27.1 KB)

What seems to be the contents of the macro was set in the mysterious property.
Can this be set programmatically?

Help me.

Best Regard.

@yuya,
Thank you for the issue description. It seems Aspose.Slides has not that ability. I have logged the issue in our tracking system with ID SLIDESNET-42479 for further invetigation. You will be notified when this feature is added.

The issues you have found earlier (filed as SLIDESNET-42479) have been fixed in this update.

@yuya,
A new API has been added to Aspose.Slides 21.5. You can use this feature for your purposes as below:

using (Presentation presentation = new Presentation())
{
    string macroName = "TestMacro";
    string macroModuleName = string.Format("{0}Module", macroName);

    IVbaProject vbaProject = new VbaProject();
    IVbaModule vbaModule = vbaProject.Modules.AddEmptyModule(macroModuleName);

    vbaModule.SourceCode = string.Format(@"
        Attribute VB_Name = ""{0}""
        Sub TestMacro()
            MsgBox ""Test completed!""
        End Sub", macroModuleName);

    presentation.VbaProject = vbaProject;

    IAutoShape shape = presentation.Slides[0].Shapes.AddAutoShape(ShapeType.BlankButton, 20, 20, 80, 30);
    shape.HyperlinkManager.SetMacroHyperlinkClick(macroName);

    presentation.Save(dataPath + "result.pptm", SaveFormat.Pptm);
}

API Reference: HyperlinkManager.SetMacroHyperlinkClick Method

1 Like