aminchicago
New Member
- Joined
- Apr 6, 2024
- Messages
- 3
- Office Version
- 365
- Platform
- MacOS
Hi! I am not a developer, but trying to use this video and its comments to install a macro (on a mac) that extracts selected text and its associated comment. The following macro works for comments, but does not include the selected text. My attempts to use other macros found on this site and elsewhere haven't worked at all. Would anyone be able to suggest a line of code that would include the selected text in the macro? I'd really appreciate it!
Sub CopyCommentsToExcel()
'Create in Word vba
Dim xlApp As Object
Dim xlWB As Object
Dim i As Integer
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err Then
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo 0
xlApp.Application.Visible = True
Set xlWB = xlApp.Application.Workbooks.Add ' create a new workbook
With xlWB.Worksheets(1)
For i = 1 To ActiveDocument.Comments.Count
.Cells(i, 1).Formula = ActiveDocument.Comments(i).Initial
.Cells(i, 2).Value = ActiveDocument.Comments(i).Range.Text 'Comment Text
Next i
End With
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
Sub CopyCommentsToExcel()
'Create in Word vba
Dim xlApp As Object
Dim xlWB As Object
Dim i As Integer
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err Then
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo 0
xlApp.Application.Visible = True
Set xlWB = xlApp.Application.Workbooks.Add ' create a new workbook
With xlWB.Worksheets(1)
For i = 1 To ActiveDocument.Comments.Count
.Cells(i, 1).Formula = ActiveDocument.Comments(i).Initial
.Cells(i, 2).Value = ActiveDocument.Comments(i).Range.Text 'Comment Text
Next i
End With
Set xlWB = Nothing
Set xlApp = Nothing
End Sub