Check if there is comment in a cell

image description

Function ThereIsCommentInCell(pColumn&, pRow&) As Boolean
	ThereIsCommentInCell = True
	Dim oAnnotation As Variant
	oAnnotation = ThisComponent.CurrentController.ActiveSheet.getCellByPosition(pColumn, pRow).getAnnotation()
	If 	oAnnotation.getString() = "" Then
		ThereIsCommentInCell = False
	End If
End Function

Sub Test
	MsgBox "ThereIsCommentInCell(0, 0) = " & ThereIsCommentInCell(0, 0),,"Function"
	MsgBox "ThereIsCommentInCell(0, 1) = " & ThereIsCommentInCell(0, 1),,"Function"
End Sub

Is there any better way to check the comment instead of checking the content of comment as I did ?

No need If-Then (without Else), just

ThereIsCommentInCell = (Trim(oAnnotation.getString()) <> "")

Other samples see here and there

Dear @JohnSUN,

Thank you so much.


doc = ThisComponent
sheet = doc.CurrentController.ActiveSheet
cell = sheet.getCellByPosition( indexColumn , indexRow )
ThereIsCommentInCell = cell.queryContentCells( 8 ).Count > 0

works also from Cell-Ranges

@karolus You probably meant <>0. Because =0 is ThereIs_NO_CommentInCell

@JohnSun: Yes of course, my Fault, I’ll change my Answer