Skip to Content
author's profile photo Former Member
Former Member

Excel cell comments via ole object

Hi guys,

just a quick question: is it possible to create a cell with a comment using abap ole object?

tried with

SET PROPERTY OF cells 'Comments' = 'Test comment'


but, obviously without success

Regards

Francesco

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jul 29, 2015 at 12:16 PM

    Dear Giordano,

    Please test below code.

    DATA: obj_esheet        TYPE ole2_object,
          obj_eapplication  TYPE ole2_object,
          obj_ecell         TYPE ole2_object,
          obj_eworkbook     TYPE ole2_object,
          obj_erange        TYPE ole2_object,
          obj_ecomment     TYPE ole2_object,
          obj_etext        TYPE ole2_object.
    
    DATA: save_path         TYPE string VALUE 'D:\OLE_Excel.xlsx'.
    
    CREATE OBJECT obj_esheet 'excel.sheet'.
    
    CALL METHOD OF
      obj_esheet
      'Application' = obj_eapplication.
    
    SET PROPERTY OF obj_eapplication 'Visible' = 1.
    CALL METHOD OF
      obj_eapplication
      'Cells' = obj_ecell
      EXPORTING
        #1 = 1
        #2 = 1.
    
    SET PROPERTY OF obj_ecell 'Value' = 'TEST Comments'.
    CALL METHOD OF obj_eapplication 'Range' = obj_erange
      EXPORTING
      #1 = 'A1'
      #2 = 'A1'.
    
    CALL METHOD OF obj_erange 'Select'.
    
    CALL METHOD OF obj_erange 'AddComment'.
    
    CALL METHOD OF obj_erange 'Comment' = obj_ecomment.
    SET PROPERTY OF obj_ecomment 'Visible' = 1.
    
    CALL METHOD OF obj_ecomment 'Text' = obj_etext
      EXPORTING
      #1 = 'Comments'.
    
    GET PROPERTY OF obj_eapplication
      'ActiveWorkbook' = obj_eworkbook.
    
    CALL METHOD OF
      obj_eworkbook
      'SAVEAS'
      EXPORTING
      #1 = save_path.
    
    FREE OBJECT obj_eapplication.
    FREE OBJECT obj_eworkbook.
    FREE OBJECT obj_esheet.
    FREE OBJECT obj_ecell.
    

    Thanks and Best Regards,

    Faisal

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 29, 2015 at 11:25 AM

    Hello!

    Try to get Range object for the cell to which you want to add comment. Then get object Comment of the Range and set it's property Text.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.