Export comments and corresponding text from MS Word to Excel

alimair

New Member
Joined
Jul 30, 2014
Messages
12
Hello,

I'm looking for a way to export comments from MS Word and display them in Excel alongside the corresponding highlighted text, with one text/comment pair per row. I think a macro should be able to achieve this pretty easily but I'm not very good at that sort of thing. Can anyone help?

Thanks,

Ali
 
Hmmm. What version of Office are you using?

You need Word, Excel and Office object libraries selected.

I can't see why it wouldn't work with v12 actually, none of the objects are particularly new. Does it give you an error when you try and use it?

/AJ
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Yes - it says "Compile error - User-defined type not defined" when I run it. It's the 2007 version I'm using.

Thanks,

Ali
 
Upvote 0
Oh hold on... I've managed to run it now, sorry, I had the MS Office Object Library selected and the Excel one, but not the Word one - so it does work with 12.0! It's great, but there's one more thing... sorry to be a pain... at the moment the comments from Word also display as comments in Excel - is it possible to have them displayed in the cell next to the corresponding text instead (i.e. column B)?

Thanks so much!

Ali
 
Upvote 0
Ah that is excellent news. And yes, sure. Updated code...

Code:
Option Explicit


Public Sub FindWordComments()
'Requires reference to Microsoft Word v14.0 Object Library


    Dim myWord              As Word.Application
    Dim myDoc               As Word.Document
    Dim thisComment         As Word.Comment
    
    Dim fDialog             As Office.FileDialog
    Dim varFile             As Variant
    
    Dim destSheet           As Worksheet
    Dim rowToUse            As Integer
    Dim colToUse            As Long
    
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    Set destSheet = ThisWorkbook.Sheets("Sheet1")
    colToUse = 1
    
    ActiveSheet
    
    With fDialog
        .AllowMultiSelect = True
        .Title = "Import Files"
        .Filters.Clear
        .Filters.Add "Word Documents", "*.docx"
        .Filters.Add "Word Macro Documents", "*.docm"
        .Filters.Add "All Files", "*.*"
    End With
    
    If fDialog.Show Then
    
        For Each varFile In fDialog.SelectedItems
    
            rowToUse = 2
    
            Set myWord = New Word.Application
            Set myDoc = myWord.Documents.Open(varFile)
    
            For Each thisComment In myDoc.Comments
            
                With thisComment
                    destSheet.Cells(rowToUse, colToUse).Value = .Scope.Text
                    destSheet.Cells(rowToUse, colToUse + 1).Value = Range.Text
                End With
                
                rowToUse = rowToUse + 1
                
            Next thisComment
            
            destSheet.Cells(1, colToUse).Value = "Comments from " & myDoc.Name
            
            Set myDoc = Nothing
            myWord.Quit
            
            colToUse = colToUse + 2
            
        Next varFile
    
    End If

End Sub

/AJ
 
Upvote 0
Oh no! Now I'm getting an error message saying "Compile error: Invalid use of property" - the line that says ActiveSheet is selected when the error message comes up...
 
Upvote 0
Thanks! Okay now I have an error message with this line:

destSheet.Cells(rowToUse, colToUse + 1).Value = Range.Text

"Range" is highlighted and it sas "Compile error: Argument not optional"
 
Upvote 0
Put a dot in front of Range
Code:
destSheet.Cells(rowToUse, colToUse + 1).Value = .Range.Text

AJ
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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