user3169544
user3169544

Reputation: 1

Powerpoint add-on to get text in notes in slides and convert it to audio. Doesn't seem to be getting the notes in the slides like it should?

Here is the code I've been working on. I imagine it should display a message box with the notes in slides but it doesn't. Also I'm not sure how to implement the speech synthesis with the code I have some of it in but could be in the wrong place.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using System.Speech.Synthesis;


namespace FirstPowerPointAddIn
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e) 
{


         SpeechSynthesizer synth = new SpeechSynthesizer();
        // Configure the audio output. 
        synth.SetOutputToDefaultAudioDevice();

     PowerPoint.Application oPowerPoint = null;
     try
      {
            oPowerPoint.SlideShowBegin += oPowerPoint_SlideShowBegin;



            oPowerPoint.SlideShowNextSlide += oPowerPoint_SlideShowNextSlide;

       }
        catch(Exception)
        {
            Console.WriteLine("error");
        }
    }



    private void ThisAddIn_Shutdown(object Pender, System.EventArgs e)
    {
    }



    private void oPowerPoint_SlideShowBegin(SlideShowWindow Wn) 

     // If the slide has notes, get the notes
    {
        if (Wn.View.Slide.HasNotesPage == Microsoft.Office.Core.MsoTriState.msoTrue)
        {

            if (Wn.View.Slide.NotesPage.Shapes[2].TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)

                System.Windows.Forms.MessageBox.Show(Wn.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text);



        }
    }
    void oPowerPoint_SlideShowNextSlide(PowerPoint.SlideShowWindow Wn)
    {

        if (Wn.View.Slide.HasNotesPage == Microsoft.Office.Core.MsoTriState.msoTrue)
        {

            if (Wn.View.Slide.NotesPage.Shapes[2].TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)

                System.Windows.Forms.MessageBox.Show(Wn.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text);



        }
    }

    #region VSTO generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    {
        this.Startup += new System.EventHandler(ThisAddIn_Startup);
        this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
    }

    #endregion
}

}

Upvotes: 0

Views: 1672

Answers (2)

Daniel Zahn
Daniel Zahn

Reputation: 31

C# version of Steve Rindsberg's VB code for those that are interested:

PowerPoint.SlideShowWindow  ppWindow;
PowerPoint.Slide            slide       = ppWindow.View.Slide;
if (slide.HasNotesPage == MsoTriState.msoTrue) {
    PowerPoint.SlideRange notesPages = slide.NotesPage;
    foreach (PowerPoint.Shape shape in notesPages.Shapes) {
        if (shape.Type == MsoShapeType.msoPlaceholder) {
            if (shape.PlaceholderFormat.Type == PowerPoint.PpPlaceholderType.ppPlaceholderBody) {
                Debug.WriteLine("Slide[" + slide.SlideIndex + "] Notes: [" + shape.TextFrame.TextRange.Text + "]");             
            }
        }
    }
}

Upvotes: 3

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

W/o seeing the presentation, I can't tell whether this is the issue, but you're assuming that the second shape on the notes page is the notes text placeholder. That's usually the case, but it's not necessarily the case.

In newer versions of PPT you'll want to iterate through the shapes looking for the one named Notes Placeholder # (where # is a number that may or may not be 2). The shape names will be different in older presentations. For that reason, it's usually best to do something like this:

Sub FindTheNotesText()
    Dim oSl As Slide
    Dim x As Long
    Set oSl = ActivePresentation.Slides(1)
    With oSl.NotesPage
        For x = 1 To .Shapes.Count
            With .Shapes(x)
                Debug.Print .Name
                Debug.Print .Type
                If .Type = msoPlaceholder Then
                    Debug.Print .PlaceholderFormat.Type
                    If .PlaceholderFormat.Type = ppPlaceholderBody Then
                        Debug.Print "^^^^^ This is the notes text placeholder"
                        Debug.Print .TextFrame.TextRange.Text
                    End If

                End If
            End With
        Next
    End With
End Sub

Upvotes: 0

Related Questions