Deleting Comments and Highlights upon saving a workbook

NeverALegend

New Member
Joined
Apr 18, 2017
Messages
1
I have a workbook to which I want to have a beforesave run in which I delete both comments and highlights, I have not been able to achieve it in the last few weeks, I've searched for possible solutions among other co workers, I was suggested the tracking system inside excel but this is a worksheets is based on an excel table. so far I have the following for removing the highlights and it works well, but I would like to include a way to remove the comments as well

Code:
Private Sub Workbook_BeforeSave (ByVal SaveAsUi As Boolean, Cancel As Boolean)
Workbooks("Tracking GB Calculator").Activate
Sheets("Tracking List").Select
Range("C3:C2417").Interior.Color = XlNone

End Sub

Any help is greatly appreciated
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try...

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As Boolean)
    Dim rngComments As Range
    Dim rngCell As Range

    Workbooks("Tracking GB Calculator").Activate
    Sheets("Tracking List").Select
    Range("C3:C2417").Interior.Color = xlNone
    
    On Error Resume Next
    Set rngComments = Range("C3:C2417").SpecialCells(xlCellTypeComments)
    On Error GoTo 0
    
    If Not rngComments Is Nothing Then
        For Each rngCell In rngComments
            rngCell.Comment.Delete
        Next rngCell
    End If
End Sub

However, here's an alternative, which doesn't require to activate or select...

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As Boolean)
    Dim rngComments As Range
    Dim rngCell As Range

    With Workbooks("Tracking GB Calculator").Sheets("Tracking List")
        .Range("C3:C2417").Interior.Color = xlNone
        On Error Resume Next
        Set rngComments = .Range("C3:C2417").SpecialCells(xlCellTypeComments)
        On Error GoTo 0
        If Not rngComments Is Nothing Then
            For Each rngCell In rngComments
                rngCell.Comment.Delete
            Next rngCell
        End If
    End With
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top