locked
C# PowerPoint AddIn - Open "Record Slide Show" Dialog Box programatically RRS feed

  • Question

  • Hello

    I am developing a PowerPoint 2010 AddIn and have been asked to add a reminder to the user to "Record Slide Show".

    Can anyone help me find out how to programmatically open the "Record Slide Show" dialog box and also how to detect if the user has already added a recording to the slide show please?

    Many thanks

    Trevor

    Thursday, July 25, 2013 1:13 PM

Answers

  • Hi Cindy,

    Sorry for the delay in getting back to you on this.

    Firstly, thank you very much for your help.

    Here is how I solved it.

    In my Ribbon.cs I now have this:

    public static void callRecordDialog()
            {
                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("RecordNarration");
            }

    and in my form under the record voice over button I have this:

    private void btnVoiceOverYes_Click(object sender, EventArgs e)
            {
                vCreateRibbon.callRecordDialog();
                this.Close();
            }

    and it works perfectly.

    It took me ages to get this working.

    Hopefully it will help others.

    Trev

    • Marked as answer by Trevor Daniel Wednesday, July 31, 2013 8:24 PM
    Wednesday, July 31, 2013 8:24 PM

All replies

  • Dear Fei Xue

    I think it would help everyone if you would read the questions to which you respond carefully and answer what is asked. All the replies I've seen from you so far today have had nothing to do with the actual question being asked. For one person, you provided sample code for Excel and VBA, when the request was for Word and VB Script, specifically. In this thread, you mention an event; the person does not want an event but to display a built-in dialog box.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 26, 2013 10:06 AM
  • Hi Cindy,

    Although I always appreciate help from anyone. I do have to agree with you on your point above....

    I don't suppose you have an idea of the answer possibly?

    Thanks

    Trev

    Friday, July 26, 2013 11:08 AM
  • Hi Trev

    Unfortunately, of all the core Office apps, my lack of knowledge of PowerPoint's object model is beaten only by that of how Outlook functions... <sigh>

    My recommendation, as odd as it sounds, would be to ask in the "Programming" or "PowerPoint" section on Answers:

    http://answers.microsoft.com/en-us/office/forum/powerpoint

    This is where most of the PowerPoint specialists hang out, including the devs. Don't mention C#, or VSTO, or Add-in - don't want to scare anyone. Just ask if there's a way to do this programmatically. If there is, the answer will probably come back in VBA, but that's OK. I can help translate VBA to C# if you aren't able to work it out... 


    Cindy Meister, VSTO/Word MVP, my blog


    Friday, July 26, 2013 11:14 AM
  • Many thanks.

    I will do that now.

    Trev

    Friday, July 26, 2013 11:25 AM
  • Hi Cindy,

    Sorry, me again :)

    I did as you suggested and have had an answer back :) and as you suspected it's VBA.

    Can you help me get it into c#?

    This is what they said:

    "CommandBars.ExecuteMso ("RecordNarration") - Should open the dialog

    IF the slide has on click animations they will run automatically if the show is recorded and there will be a TAG named "TIMING" that holds the recorded values. You may also see that transition times are values like 2.67 instead of 3 seconds."

    Trev

    Friday, July 26, 2013 12:44 PM
  • Hi Trev

    My, that was fast :-) And the answer makes sense, as in: I really should have been able to come up with that... <sigh>

    OK, so CommandBars is a property of the Application object (across all the Office apps, by-the-by) and is inherited from the Microsoft.Office.Core namespace.

    The C# code in an add-in would look like this:

      this.Application.CommandBars.ExecuteMso("Record Narration");


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 26, 2013 1:37 PM
  • Hi Cindy,

    I'm really sorry. I cannot seem to get it working. I'm quite new to WinForms :(

    I have added

    using Microsoft.Office.Core;

    I have then added your code:

    this.Application.CommandBars.ExecuteMso("Record Narration");

    But I get the error:

    Error 1 'vCreate.frmVoiceOver' does not contain a definition for 'Application' and no extension method 'Application' accepting a first argument of type 'vCreate.frmVoiceOver' could be found (are you missing a using directive or an assembly reference?)

    This is my complete code:

    private void btnVoiceOverYes_Click(object sender, EventArgs e)
            {
                //Microsoft.Office.Core._CommandBars.ExecuteMso("Record Narration");
                this.Application.CommandBars.ExecuteMso("Record Narration");
                
            }

    Any idea what I am doing wrong?

    Trev

    Friday, July 26, 2013 3:35 PM
  • The problem is that you're calling this from "the outside", from a Windows Form and not from code that's "inside" the add-in (a Ribbon button, for example).

    The Windows Form has no idea that it belongs to the add-in; it doesn't recognize "this" as being the add-in, as it would if the code were in the ThisAddin class. In the Windows Form, "this" means the Windows Form.

    You have to create a custom constructor for the Windows form and pass something to it that can be used to communicate with the add-in. Usually, I'd pass in the Office application instance the add-in is running in, something along these lines:

    Form1 f = new Form1(this.Application.InnerObject).Show();

    Then you'd have a class level object for the PowerPoint application in the Windows Form class:

    Microsoft.Office.Interop.PowerPoint pApp = null;

    And the constructor would be something like:

    public void Form1(Microsoft.Office.Interop.PowerPoint app)
    {
        pApp = app;
    }

    Then in the button click event:

    pApp.CommandBars.ExecuteMso("Record Narration");


    Cindy Meister, VSTO/Word MVP, my blog

    • Proposed as answer by Jeffrey_Chen_ Tuesday, July 30, 2013 8:19 AM
    Friday, July 26, 2013 3:58 PM
  • Hi Cindy,

    Sorry for the delay in getting back to you on this.

    Firstly, thank you very much for your help.

    Here is how I solved it.

    In my Ribbon.cs I now have this:

    public static void callRecordDialog()
            {
                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("RecordNarration");
            }

    and in my form under the record voice over button I have this:

    private void btnVoiceOverYes_Click(object sender, EventArgs e)
            {
                vCreateRibbon.callRecordDialog();
                this.Close();
            }

    and it works perfectly.

    It took me ages to get this working.

    Hopefully it will help others.

    Trev

    • Marked as answer by Trevor Daniel Wednesday, July 31, 2013 8:24 PM
    Wednesday, July 31, 2013 8:24 PM