CellCommentRead + Save

Reads/Saves a comment into a cell
CellCommentRead to Reads comment from a cell
CellCommentSave to add/edit/delete comment from a cell
If NewComment="" then it will be deleted

CodeFunctionName
What is this?

Public

Tested

Original Work
Function CellCommentSave(Addr, Optional NewComment = "", Optional Shee = "Active", Optional WB = "This")
' Adds/Edits/Deletes comment from a cell
' If NewComment="" then it will be deleted
If Shee = "Active" Then Shee = ActiveSheet.Name
If WB = "This" Then WB = ThisWorkbook.Name
If WB = "Active" Then WB = ActiveWorkbook.Name
Dele = 0
If NewComment = "" Then Dele = 1
CurrComment = ""
HasComment = 0
Err.Clear
On Error Resume Next
CurrComment = Workbooks(WB).Worksheets(Shee).Range(Addr).Comment.Text
If CurrComment > "" Then HasComment = 1
On Error GoTo 0
Err.Clear
If HasComment + Dele = 2 Then
Workbooks(WB).Worksheets(Shee).Range(Addr).Comment.Delete
ElseIf HasComment + Dele = 0 Then
Workbooks(WB).Worksheets(Shee).Range(Addr).AddComment NewComment
ElseIf HasComment = 1 And Dele = 0 Then
Workbooks(WB).Worksheets(Shee).Range(Addr).Comment.Text NewComment
End If
End Function
Function CellCommentRead(Addr, Optional Shee = "Active", Optional WB = "This")
' Reads comment from a cell
If Shee = "Active" Then Shee = ActiveSheet.Name
If WB = "This" Then WB = ThisWorkbook.Name
If WB = "Active" Then WB = ActiveWorkbook.Name
MyComm = ""
Err.Clear
On Error Resume Next
CurrComment = Workbooks(WB).Worksheets(Shee).Range(Addr).Comment.Text
If CurrComment > "" Then MyComm = CurrComment
On Error GoTo 0
Err.Clear
CellCommentRead = MyComm
End Function

Addr, Optional Shee, Optional WB
Or
Addr, Optional NewComment, Optional Shee, Optional WB

Views 2,970

Downloads 1,190

CodeID
DB ID

ANmarAmdeen
602
Attachments
Revisions

v1.0

Sunday
June
17
2018