The following code will add a comment in a particular cell in Excel worksheet.
Set oExcel=CreateObject("Excel.Application")
oExcel.Visible=True
Set oWorkBook=oExcel.Workbooks.Add
Set oWorkSheet=oWorkBook.Worksheets(1)
With oWorkSheet.Cells(1,1).AddComment
.Visible = False
.Text "Comment for Cell 1,1"
End With
oExcel.Visible=True
Set oWorkBook=oExcel.Workbooks.Add
Set oWorkSheet=oWorkBook.Worksheets(1)
With oWorkSheet.Cells(1,1).AddComment
.Visible = False
.Text "Comment for Cell 1,1"
End With
In case, you want to update the comment, use the following code:
With oWorkSheet.Cells(1,1).Comment
.Visible = True
.Text "Comment Text Changed"
End With
This post first appeared on QTP: Expert In HP QuickTest Professional (QTP), please read the originial post: here