Skip to Content

Excel cell comments via ole object - get comments in excel sheet

Hi, is it possible to get a comment text of a cell using abap ole object?

I already read this:

https://archive.sap.com/discussions/thread/3777521

but it's addcomment. I want read or get comment.

I tried with

DATA: obj_erange TYPE ole2_object,
obj_ecomment TYPE ole2_object.

* CALL METHOD OF application 'Range' = obj_erange
* EXPORTING
* #1 = 'A1'
* #2 = 'A1'.

CALL METHOD OF worksheet 'Cells' = h_cell
EXPORTING #1 = 1 #2 = 1.
m_message.
CALL METHOD OF worksheet 'Cells' = h_cell1
EXPORTING #1 = 1 #2 = 1.
m_message.

CALL METHOD OF worksheet 'RANGE' = obj_erange
EXPORTING #1 = h_cell #2 = h_cell1.
m_message.

CALL METHOD OF obj_erange 'Select'.

CALL METHOD OF obj_erange 'Comment' = obj_ecomment.

CALL METHOD OF obj_ecomment 'COPY'.

CALL METHOD cl_gui_frontend_services=>clipboard_import
IMPORTING
data = excel_tab
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.

But, it was not work.

Please, let me know.

I searched at

https://docs.microsoft.com/

but, I couldn't find solution.

CALL METHOD OF obj_erange 'Comment' = obj_ecomment.

This is failed, too.

How can I get comments in worksheet ???

Somebody help me, please !!!!!! OTL

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Feb 11 at 06:04 AM

    You should explain what means "it doesn't work" (which line of code returns the error code...)

    By using the Excel macros (alt+F11), this VBA code works, just translate it to ABAP:

    Set cell = Cells(1, 2)
    Text = cell.Comment.Text
    

    So, I guess you have 2 main errors :

    1) the worksheet object doesn't have any RANGE method. Anyway you don't need it because CELLS is a range object !

    2) you forget the TEXT property : don't copy the COMMENT object, do :

    DATA comment_text TYPE c LENGTH 255.
    GET PROPERTY OF obj_ecomment 'text' = comment_text.

    PS: you don't need the clipboard too.

    Add comment
    10|10000 characters needed characters exceeded