Excel VBA - Comments (Add, Edit, Delete, Delete All, Show, Hide, Show All, Hide All)

Опубликовано: 31 Март 2026
на канале: The World Of Algorithms
724
like

💡 Source Code

Const e_msg As String = "The process was aborted because no comment was found in the active cell"

Sub NewComment()
With ActiveCell
.AddComment
.Comment.Visible = False
.Comment.Text Text:=Application.UserName
End With
MsgBox "A comment has been added to the active cell", vbInformation + vbOKOnly, ""
End Sub

Sub EditComment()
Dim new_comment As String
If ActiveCell.Comment Is Nothing Then
MsgBox e_msg, vbExclamation + vbOKOnly, ""
Else:
new_comment = InputBox("Your comment...", "", "")
ActiveCell.Comment.Text Text:=new_comment
End If
End Sub

Sub ShowComment()
If ActiveCell.Comment Is Nothing Then
MsgBox e_msg, vbExclamation + vbOKOnly, ""
Else:
ActiveCell.Comment.Visible = True
End If
End Sub

Sub HideComment()
If ActiveCell.Comment Is Nothing Then
MsgBox e_msg, vbExclamation + vbOKOnly, ""
Else:
ActiveCell.Comment.Visible = False
End If
End Sub

Sub ShowAllComments()
Application.DisplayCommentIndicator = xlCommentAndIndicator
End Sub

Sub HideAllComments()
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End Sub

Sub DeleteComment()
If ActiveCell.Comment Is Nothing Then
MsgBox e_msg, vbExclamation + vbOKOnly, ""
Else:
ActiveCell.ClearComments
MsgBox "The comment in the active cell has been deleted", vbInformation + vbOKOnly, ""
End If
End Sub

Sub DeleteAllComments()
On Error Resume Next
Selection.SpecialCells(xlCellTypeComments).Select
Selection.ClearComments
End Sub
------------------------------------------------------------------------------------------

#excel
#msexcel
#msexceltutorial
#msexcelcourse
#vba
#vbatutorial
#excelvba
#fulltutorial
#excelvbatutorial
#microsoftexceltutorial
#tutorial
#exceltutorial
#advancedexcel
#advancedexceltraining
#algorithm
#algorithms
#programming
#program
#script
#vbamacro
#vbamacros
#usingmacro
#veryuseful
#useful
#veryusefulmacro
#freeeducation
#freeprogramming
#freelancer
#excelfreelancer
#vbafreelancer
#freelanceservices
#comment
#excelcomment
#excelvbacomment
#comments
#addcomment
#exceladdcomment
#newcomment
#excelnewcomment
#insertacomment
#excelinsertacomment
#edit
#editcomment
#exceleditcomment
#delete
#deletecomment
#exceldeletecomment
#deleteall
#deleteallcomments
#exceldeleteallcomments
#show
#showcomment
#excelshowcomment
#showcomments
#showallcomments
#excelshowallcomments
#excelhidecomment
#hidecomment
#hideallcomments
#excelhideallcomments