Remove Excel Comment from a Perticular Column

Hi All,

I’m trying to remove only the comment/note from a particular Excel cell (e.g., B5) using UiPath without deleting the cell value.

I tried the Invoke VBA approach with the below code:

vba

CopyEdit

Sub ClearComment()
    Dim targetCell As Range
    Set targetCell = Range("B5")
    
    On Error Resume Next
    targetCell.Comment.Delete       ' Old style comments
    targetCell.ClearComments        ' New threaded comments
    On Error GoTo 0
End Sub

I saved this in a .txt file and used Invoke VBA in UiPath, but I get the error:

Trust access to the VBA project object model must be enabled in Trust Center settings

I already enabled File → Options → Trust Center → Trust Center Settings → Macro Settings → Trust access to the VBA project object model, but the error still appears.
I think this could be due to organization group policies or macro restrictions.

please help with some else technique as i tried read cell and write cell to a different column of course that does the job but to a different cell not to the same cell

even if you do

read cell value

and write cell at the same column as “”

then again take the output of read cell value still the comment is there

i just need to delte the comment in a perticular cell how we can do it

Regards
Rahul

Hi @Rahul_Singh_Kamboj

Use the Clear Sheet/Range/Table activity to remove the data from the specified range.

Dear @Rahul_Singh_Kamboj,

The VB code you have written is causing problem.
Please you below VB code & activity as shown.

Function ClearComment(cellAddress as string) As String
On Error goto ErrorHandling:
Range(cellAddress).Select
Selection.ClearComments
Exit Function
ErrorHandling:
Result = "Error"
End Function

Dont forgot to mark save changes flag in Use excel file activity.

Trust center setting:

Activity Snip:

Mark as solution if it solves your issue :slight_smile:

Br,
NikZ