Suppose you have a workbook with a ton of cell comments, but you want to give a copy to someone without all the comments. Here's some simple code to remove all comments from a workbook. In this case, I assume it the ActiveWorkbook.
VBA Code
Sub DeleteAllComments()
On Error GoTo ErrMsg:
For Each ws In ActiveWorkbook.Sheets
ws.Cells.ClearComments
Next ws
MsgBox "Done!", vbInformation, "DeleteAllComments()"
ExitHere:
Exit Sub
ErrMsg:
MsgBox Err.Number & ": " & Err.Description, _
vbExclamation, "DeleteAllComments()"
GoTo ExitHere
End Sub
Links
- Workbook Object: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/workbook-object-excel
- ActiveWorkbook Property: https://msdn.microsoft.com/en-us/VBA/Excel-VBA/articles/application-activeworkbook-property-excel
- Range.ClearComments Method: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-clearcomments-method-excel