none
call a function when clicking shape powerpoint while sliding csharp RRS feed

  • Question

  • I know that we can add an action when clicking a shape while sliding by ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Action in Csharp like my code below:

    aromaClick =thisSlide.Shapes.AddShape(Office.MsoAutoShapeType.msoShape24pointStar, 10, 10, 20, 20); Globals.ThisAddIn.aromaClick.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Action = PowerPoint.PpActionType.ppActionRunProgram;

    Globals.ThisAddIn.aromaClick.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Run = "path-to-file";

    but I wonder if I can call a function when click-shape happens? is it possible? like call this function:

    void hello()

    {

    //something }

    thank you!

    Friday, December 25, 2015 3:46 AM

Answers

  • >>>But do you know any other choices I can do with clicking something in presentation mode? I just need receiving a click-something event to call a function already built in my source code. It can be a shape, a text, button whatever. can U solve it?

    ActionSetting.Run Property (PowerPoint)
    If the value of the Action property is ppActionRunMacro, the specified string value should be the name of a global macro that's currently loaded. If the value of the Action property is ppActionRunProgram, the specified string value should be the full path and file name of a program.

    This is a workaround that you could dynamically add a VBA macro, refer to below code:

    Add references "Microsoft.Vbe.Interop"

    var thisSlide = Globals.ThisAddIn.Application.ActivePresentation.Slides[1];
    var aromaClick = thisSlide.Shapes.AddShape(Office.MsoAutoShapeType.msoShape24pointStar, 10, 10, 20, 20);
                
    //var test = Globals.ThisAddIn.Application.ActivePresentation.VBProject.VBComponents.Add(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule);
    //var codeModule = Globals.ThisAddIn.Application.ActivePresentation.VBProject.VBComponents.Item(1);
    var codeModule = Globals.ThisAddIn.Application.ActivePresentation.VBProject.VBComponents.Add(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule);
    StringBuilder moduleCode = new StringBuilder();
    moduleCode.AppendLine("Sub ShowInfo()");
    moduleCode.AppendLine("\t" + @"Msgbox ""Test Information""");
    moduleCode.AppendLine("End Sub");
    codeModule.CodeModule.AddFromString(moduleCode.ToString());
    aromaClick.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Action = PowerPoint.PpActionType.ppActionRunMacro;
    aromaClick.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Run = "ShowInfo";

    Note: Set File -> Options -> Trust Center -> Trust Center Setttings -> Macro Settings -> Trust Access to the VBA Project object model checked.

    For more information, click here to refer about ActionSetting.Run Property (PowerPoint)
    and here to refer about How to dynamically add and run a VBA macro from Visual Basic


    Monday, December 28, 2015 5:56 AM

All replies

  • VSTO doesn't provide anything for that. Moreover, the PowerPoint object model doesn't provide such events. The ActionSetting.Run property allows to set the name of the presentation or macro to be run when the specified shape is clicked or the mouse pointer passes over the shape during a slide show. 

    I'd suggest asking PowerPoint specific questions on the General Office Development  forum instead.

    Friday, December 25, 2015 4:39 PM
  • thank you for your kind help!

    But do you know any other choices I can do with clicking something in presentation mode? I just need receiving a click-something event to call a function already built in my source code. It can be a shape, a text, button whatever. can U solve it?

    Saturday, December 26, 2015 5:19 PM
  • >>>But do you know any other choices I can do with clicking something in presentation mode? I just need receiving a click-something event to call a function already built in my source code. It can be a shape, a text, button whatever. can U solve it?

    ActionSetting.Run Property (PowerPoint)
    If the value of the Action property is ppActionRunMacro, the specified string value should be the name of a global macro that's currently loaded. If the value of the Action property is ppActionRunProgram, the specified string value should be the full path and file name of a program.

    This is a workaround that you could dynamically add a VBA macro, refer to below code:

    Add references "Microsoft.Vbe.Interop"

    var thisSlide = Globals.ThisAddIn.Application.ActivePresentation.Slides[1];
    var aromaClick = thisSlide.Shapes.AddShape(Office.MsoAutoShapeType.msoShape24pointStar, 10, 10, 20, 20);
                
    //var test = Globals.ThisAddIn.Application.ActivePresentation.VBProject.VBComponents.Add(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule);
    //var codeModule = Globals.ThisAddIn.Application.ActivePresentation.VBProject.VBComponents.Item(1);
    var codeModule = Globals.ThisAddIn.Application.ActivePresentation.VBProject.VBComponents.Add(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule);
    StringBuilder moduleCode = new StringBuilder();
    moduleCode.AppendLine("Sub ShowInfo()");
    moduleCode.AppendLine("\t" + @"Msgbox ""Test Information""");
    moduleCode.AppendLine("End Sub");
    codeModule.CodeModule.AddFromString(moduleCode.ToString());
    aromaClick.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Action = PowerPoint.PpActionType.ppActionRunMacro;
    aromaClick.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Run = "ShowInfo";

    Note: Set File -> Options -> Trust Center -> Trust Center Setttings -> Macro Settings -> Trust Access to the VBA Project object model checked.

    For more information, click here to refer about ActionSetting.Run Property (PowerPoint)
    and here to refer about How to dynamically add and run a VBA macro from Visual Basic


    Monday, December 28, 2015 5:56 AM