• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

VB.net Excel problem reading the comments in cells

Hi

I am trying to use the following code to read the comment in an Excel cell
but get the error shown in the image

Dim S As String = Globals.ThisAddIn.Application.ActiveCell.Comment
MsgBox(S)
Image1.jpg
0
Murray Brown
Asked:
Murray Brown
  • 2
2 Solutions
 
Pratima PharandeCommented:
I tried this

Dim S As String
S = ActiveCell.Comment.Text
MsgBox (S)

working fine

try
Dim S As String = Globals.ThisAddIn.Application.ActiveCell.Comment.Text
MsgBox(S)
0
 
Pratima PharandeCommented:
if comment text empty then also it is throwing error

then I tried this working fine

Dim S As String
 On Error Resume Next

S = ActiveCell.Comment.Text
MsgBox (S)
0
 
Rgonzo1971Commented:
Hi,

First you have to test whether there is a comment and then read it

If ActiveCell.Comment Is Nothing Then
MsgBox ("empty")
Else
MsgBox (ActiveCell.Comment.Text)
End If

Open in new window

Regards
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thank you both
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now