VBA to Create a Report of Cell Comments, Take 2

lneidorf

Board Regular
Joined
May 20, 2004
Messages
97
Office Version
  1. 365
Platform
  1. Windows
Hi there.

I'm attempting to create a user-friendly macro-enabled spreadsheet ("Comments Recap v2.xlsm") that will generate a report of the Excel cell Comments in selected Excel workbooks.

The goal is for my users to open my file, click a button, be promoted to select wither a single file or a folder full of files. After that, the file(s) will be analyzed, and a report on their cell comments will appear on a tab of my file.

The report, appearing on a tab entitled "Comment Recap", lists File Name, Sheet Name, Cell Address, Cell Value, and the actual Comment content.

Where there are multiple files, the report of their cell comments will appear on that same "Comment recap" tab, appended beneath any prior data.

I've been playing around with this a bunch, but no success as yet.

Here's my most recent code, this version intended to prompt the user to select a single file for evaluation:

Code:
Sub ShowCommentsAllSheetsRevised3()
'Adapted from https://www.extendoffice.com/documents/excel/679-list-all-comments-workbook.html
Dim commrange As Range
Dim rng As Range

Dim swb As Workbook, wb As Workbook
Dim sws As Worksheet, ws As Worksheet
Dim Lastrow As Integer
Set swb = ThisWorkbook
Set sws = swb.Worksheets("Comment Recap")

    'Open File for Evaluation
    Dim fNameAndPath As Variant
    fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLS*), *.XLS*", Title:="Select File To Be Opened")
    If fNameAndPath = False Then Exit Sub
    Set wb = Workbooks.Open(Filename:=fNameAndPath, UpdateLinks:=0)

sws.Range("A1").Resize(1, 5).Value = Array("File Name", "Sheet Name", "Cell Address", "Cell Value", "Comment")
On Error Resume Next
For Each ws In Application.ActiveWorkbook.Worksheets
    Set commrange = ws.Cells.SpecialCells(xlCellTypeComments)
    If Not commrange Is Nothing Then
        i = sws.Cells(Rows.Count, 1).End(xlUp).Row
        For Each rng In commrange
            i = i + 1
            swb.Cells(i, 1).Resize(1, 5).Value = Array(ActiveWorkbook.Name, ws.Name, rng.Address, rng.Value, rng.Comment.Text)
        Next
    End If
    Set commrange = Nothing
Next

End Sub

I create many utilities for use by my colleagues. They typically contain a tab ("Dashboard") where there are instructions and options as well as buttons for my users to run a macro/macros across other files. With my code, I often struggle with making references to other files intended for evaluation / processing. I think that's a problem with my code here.

I've got additional code for running code across the contents of an entire folder. I'm fairly confident that I can adapt this for that purpose if I can get this to work.

Any help you can offer would be most appreciated.

Thanks!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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