How to extract comments to Word from a specific keyword

potnoodle

New Member
Joined
Sep 14, 2017
Messages
2
Hi Guys
I need to extract comments from an Excel workbook based on a name - we are using the comments feature to add data to how a student has behaved that day, ie George was a pain in the butt :). I have found the code online to extract all of the comments in the sheet to Word, how can I amend this to just look for those with a students name i.e. George in the comment? Many thanks in advance

Sub CopyCommentsToWord()



Dim xComment As Comment
Dim wApp As Object
On Error Resume Next
Set wApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
Set wApp = CreateObject("Word.Application")
End If
wApp.Visible = True
wApp.Documents.Add DocumentType:=0
For Each xComment In Application.ActiveSheet.Comments
wApp.Selection.TypeText xComment.Parent.Address & vbTab & xComment.Text
wApp.Selection.TypeParagraph
Next
Set wApp = Nothing
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi Guys
I need to extract comments from an Excel workbook based on a name - we are using the comments feature to add data to how a student has behaved that day, ie George was a pain in the butt :). I have found the code online to extract all of the comments in the sheet to Word, how can I amend this to just look for those with a students name i.e. George in the comment? Many thanks in advance

The comment text is in the comments Text property, so something like this should work.

Code:
Sub CopyCommentsToWord()
Dim xComment As Comment
Dim wApp As Object

On Error Resume Next

Set wApp = GetObject(, "Word.Application")

If Err.Number <> 0 Then
     Err.Clear
     Set wApp = CreateObject("Word.Application")
End If

wApp.Visible = True

wApp.Documents.Add DocumentType:=0

For Each xComment In Application.ActiveSheet.Comments
    If instr(xComment.Text, "George") then
         wApp.Selection.TypeText xComment.Parent.Address & vbTab & xComment.Text
         wApp.Selection.TypeParagraph
    End If
Next

Set wApp = Nothing

End Sub

I hope that helps!
 
Upvote 0
The comment text is in the comments Text property, so something like this should work.

Code:
Sub CopyCommentsToWord()
Dim xComment As Comment
Dim wApp As Object

On Error Resume Next

Set wApp = GetObject(, "Word.Application")

If Err.Number <> 0 Then
     Err.Clear
     Set wApp = CreateObject("Word.Application")
End If

wApp.Visible = True

wApp.Documents.Add DocumentType:=0

For Each xComment In Application.ActiveSheet.Comments
    If instr(xComment.Text, "George") then
         wApp.Selection.TypeText xComment.Parent.Address & vbTab & xComment.Text
         wApp.Selection.TypeParagraph
    End If
Next

Set wApp = Nothing

End Sub

I hope that helps!

That's great many thanks Robert :)
 
Upvote 0

Forum statistics

Threads
1,223,769
Messages
6,174,418
Members
452,563
Latest member
mvdk

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