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); 


PowerPoint
PowerPoint
A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.
250 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,696 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 20,480 Reputation points
    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 **