VBA & Macro Problems

Export Excel Cell Comments to a Text File with VBA

Natalie TaylorNatalie Taylor Nov 20, 2026 869 views

Question details

Export comments from multiple Excel cells along with their cell addresses to a text file.

How to Export Excel Cell Comments to a Text File with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains hundreds of cell comments that would be time-consuming to copy manually.
Observed behavior
The user wants a text file listing each comment and its cell address.
Before you start

Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) in a folder where you can write files. Check that the worksheet contains legacy comments, called Notes in newer Excel versions, and enable macros only if you trust the workbook.

Solution 1Recommended

Export legacy comments from the active Excel worksheet

Use this macro to write each legacy comment and its cell address to a text file in the workbook folder.

The macro exports legacy comments from the active worksheet only. It does not export modern threaded comments.

1
Open the VBA editor

In Excel, select Developer > Visual Basic. On Windows, you can also press Alt+F11.

2
Insert the macro

In the VBA editor, select the target workbook, choose Insert > Module, and paste this code: Sub ExportComments() Dim c As Comment Dim fileNumber As Integer Dim outputPath As String If ThisWorkbook.Path = "" Then MsgBox "Save this workbook before exporting comments." Exit Sub End If outputPath = ThisWorkbook.Path & Application.PathSeparator & "Test.txt" fileNumber = FreeFile Open outputPath For Output As #fileNumber For Each c In ActiveSheet.Comments Print #fileNumber, c.Parent.Address(False, False) & ": " & c.Text Next c Close #fileNumber MsgBox "Export saved to: " & outputPath End Sub

3
Run the export

Return to Excel, select the worksheet containing the comments, and choose Developer > Macros. Select ExportComments and click Run.

4
Check the text file

Open Test.txt in the folder containing the workbook and check the exported cell addresses and comment text. If the file is empty, verify that the selected worksheet contains legacy comments or Notes.

Export legacy comments from the active Excel worksheet
Existing file and comment types: Running the macro replaces any existing Test.txt in the workbook folder. Modern threaded comments are not included.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface, making it easy to move everyday workbook tasks from Microsoft Office. It does not fix Excel's VBA export or guarantee that Excel macros will run unchanged.

Open and edit common Microsoft Excel formats, including XLSX and XLSReview spreadsheet data and cell annotations in a familiar interfaceUse a free, lightweight office suite for everyday spreadsheet work
microsoft office alternative - wps office

Frequently Asked Questions

Why is the exported text file empty?

The macro reads legacy comments from the active worksheet. Select the correct sheet and check whether its annotations are Notes rather than modern threaded comments.

Where does the macro save the exported comments?

It saves Test.txt in the folder containing the workbook that holds the macro. Save that workbook first and make sure you can write to its folder.

Can this macro export comments from every worksheet?

Not as written. It uses ActiveSheet.Comments, so select a worksheet and run it for that sheet. Running it again replaces Test.txt unless you change the output file name.

How do I keep the macro in my workbook?

In Excel, use File > Save As and choose Excel Macro-Enabled Workbook (.xlsm). Enable macros when opening the file only if you trust its source.