How do you get the Notes text from the current PowerPoint slide using C#?
Asked
Active
Viewed 5,721 times
2 Answers
5
I believe this might be what you are looking for:
string s = slide.NotesPage.Shapes[2].TextFrame.TextRange.Text
slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Hello World"

Crispy
- 5,557
- 3
- 30
- 35
-
HI Chris, I tried it. it works on most of the slides. except the last page, I will meet a ArgumentException. could you explain it a little bit? what's the magic 2 means here? Thank you in advance – StanleyZ Jan 25 '13 at 09:55
-
2Check this question. It has a better answer then what I provided: http://stackoverflow.com/questions/6252927/powerpoint-notes-in-c-sharp – Crispy Jan 25 '13 at 14:23
-
You should not hard code magic numbers. You cannot guarantee it will be the [2] element in the Shapes array. Probably the cause of the error on the last slide. – Simon Dec 17 '13 at 16:34
1
Here is my code that I use for getting the slide notes. Still developing it, but seems to do the trick for the time being. Even in my simple test PPT the slide notes are not always the [2] element in the shapes array, so it is important to check.
private string GetNotes(Slide slide)
{
if (slide.HasNotesPage == MsoTriState.msoFalse)
return string.Empty;
string slideNodes = string.Empty;
var notesPage = slide.NotesPage;
int length = 0;
foreach (Shape shape in notesPage.Shapes)
{
if (shape.Type == MsoShapeType.msoPlaceholder)
{
var tf = shape.TextFrame;
try
{
//Some TextFrames do not have a range
var range = tf.TextRange;
if (range.Length > length)
{ //Some have a digit in the text,
//so find the longest text item and return that
slideNodes = range.Text;
length = range.Length;
}
Marshal.ReleaseComObject(range);
}
catch (Exception)
{}
finally
{ //Ensure clear up
Marshal.ReleaseComObject(tf);
}
}
Marshal.ReleaseComObject(shape);
}
return slideNodes;
}

Simon
- 736
- 6
- 21
-
As you say, some TextFrames do not have a range, but instead of throwing an exception when you try to access it first, check if (frame.HasText == Office.MsoTriState.msoTrue). – Rob Prouse Jul 14 '15 at 19:37