When I add a comment in PowerPoint using Interop, it gives an error "Comments (unknown member) : Illegal value. "

Sudhanshu Saxena 5 Reputation points
2023-12-06T05:20:22.2133333+00:00
When I am adding a comment in Office 365 PowerPoint using Interop, it gives an error 

> Comments (unknown member): Invalid value.

My code was working for a long time, but in the last few days after the release of the latest version(2310) of Microsoft Office 365, it is not working due to this error. Is there are some change in `Microsoft.Office.Interop.PowerPoint.Slide.Comments.Add()`?


    try
      {
           Microsoft.Office.Interop.PowerPoint.Presentation doc =            Globals.ThisAddIn.Application.ActivePresentation;
           Microsoft.Office.Core.DocumentProperties properties = doc.BuiltInDocumentProperties as Microsoft.Office.Core.DocumentProperties;
           Microsoft.Office.Interop.PowerPoint.TextRange rng = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange;
           Microsoft.Office.Interop.PowerPoint.Slide sld = Globals.ThisAddIn.Application.ActivePresentation.Slides[Globals.ThisAddIn.Application.ActiveWindow.Selection.SlideRange.SlideIndex];

  string timestamp = System.DateTime.Now.ToString("yyyyMMddHHmmssFFF");
  string commentText = timestamp + ":" + text + ": ";
  string userName = System.Environment.GetEnvironmentVariable("UserName");
                
  sld.Comments.Add(900, rng.BoundLeft, userName, "", commentText);    // code break at this line
  System.Windows.Forms.SendKeys.Send("{END}");
 }
 catch (Exception ex)
 {            
    MessageBox.Show(ex.Message.ToString());
 } 

sld.Comments.Add(900, rng.BoundLeft, userName, "", commentText); 


Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | PowerPoint | For business | Windows
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Cloudoire Academy 23,595 Reputation points Volunteer Moderator
    2023-12-06T05:45:42.3266667+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    Maybe because of the order of parameters, the left should be before the top.

    https://learn.microsoft.com/en-us/previous-versions/office/office-12/ff762972(v=office.12)

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.