Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2023, 08:43 AM
DuchessNora DuchessNora is offline Exporting comments from word to excel - Comment.Parent property issue Windows 11 Exporting comments from word to excel - Comment.Parent property issue Office 2021
Novice
Exporting comments from word to excel - Comment.Parent property issue
 
Join Date: Oct 2023
Posts: 6
DuchessNora is on a distinguished road
Default Exporting comments from word to excel - Comment.Parent property issue

Hi all,

I'm trying to create a macro which can export comments from word to excel, so far I have this:

Sub ExportComments()
' Note: A reference to the Microsoft Excel # Object Library is required, set via Tools|References in the Word VBE.
Dim StrCmt As String, StrTmp As String, i As Long, j As Long, xlApp As Object, xlWkBk As Object
StrCmt = "Page,Line,Author,Date & Time,Comment,Reference Text"
StrCmt = Replace(StrCmt, ",", vbTab)
With ActiveDocument
' Process the Comments
For i = 1 To .Comments.Count
With .Comments(i)
StrCmt = StrCmt & vbCr & .Reference.Information(wdActiveEndAdjustedPageNumb er) & vbTab
StrCmt = StrCmt & .Reference.Information(wdFirstCharacterLineNumber) & vbTab & .Author & vbTab
StrCmt = StrCmt & .Date & vbTab & Replace(Replace(.Range.Text, vbTab, "<TAB>"), vbCr, "<P>")
StrCmt = StrCmt & vbTab & Replace(Replace(.Scope.Text, vbTab, "<TAB>"), vbCr, "<P>")


StrCmt = StrCmt & vbTab & IIf(.Parent Is Nothing, "Not a Parent", "Is a Parent")
StrCmt = StrCmt & vbTab & IIf(.Done, "Resolved", "Not Resolved")

End With
Next
End With
' Test whether Excel is already running.
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
'Start Excel if it isn't running
If xlApp Is Nothing Then
Set xlApp = CreateObject("Excel.Application")
If xlApp Is Nothing Then
MsgBox "Can't start Excel.", vbExclamation
Exit Sub
End If
End If
On Error GoTo 0
With xlApp
Set xlWkBk = .Workbooks.Add
' Update the workbook.
With xlWkBk.Worksheets(1)
For i = 0 To UBound(Split(StrCmt, vbCr))
StrTmp = Split(StrCmt, vbCr)(i)
For j = 0 To UBound(Split(StrTmp, vbTab))
.Cells(i + 1, j + 1).Value = Split(StrTmp, vbTab)(j)
Next
Next
.Columns("A: D").AutoFit
End With
' Tell the user we're done.
MsgBox "Workbook updates finished.", vbOKOnly
' Switch to the Excel workbook
.Visible = True
End With
' Release object memory
Set xlWkBk = Nothing: Set xlApp = Nothing
End Sub



However the (StrCmt = StrCmt & vbTab & IIf(.Parent Is Nothing, "Not a Parent", "Is a Parent") property doesn't actually show whether the comment is a parent or not (it labels all of them as parents, even the responses) so I need to replace it with StrCmt = StrCmt & vbTab & IIf(.Replies = 0, "Not a Parent", "Is a Parent"). When I tried replacing and running the macro again I get an error popping up saying "compile error argument not optional". I'm not familiar with coding language so would anyone be able to help me figure out how to fix this? thank you!
Reply With Quote
  #2  
Old 10-24-2023, 08:56 AM
Italophile Italophile is offline Exporting comments from word to excel - Comment.Parent property issue Windows 11 Exporting comments from word to excel - Comment.Parent property issue Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

You need
Code:
StrCmt = StrCmt & vbTab & IIf(.Replies.Count = 0, "Not a Parent", "Is a Parent")
Reply With Quote
  #3  
Old 10-24-2023, 02:53 PM
Guessed's Avatar
Guessed Guessed is offline Exporting comments from word to excel - Comment.Parent property issue Windows 10 Exporting comments from word to excel - Comment.Parent property issue Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I think your logic is flawed. Having no replies doesn't mean the comment is a child-level comment. Instead you should be looking for presence of an Ancestor - top level comments don't have an ancestor. Then you can loop through any replies if they exist. Here is a snippet of code I'm currently using...
Code:
      For Each aCmt In wdDoc.Comments
        If aCmt.Ancestor Is Nothing Then        'a top level comment
           'do something
          If aCmt.Replies.Count > 0 Then
            For i = 1 To aCmt.Replies.Count
              Set aReply = aCmt.Replies(i)
              'do something with the replies
            Next i
          End If
        End If
      Next aCmt
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 10-25-2023, 01:13 AM
DuchessNora DuchessNora is offline Exporting comments from word to excel - Comment.Parent property issue Windows 11 Exporting comments from word to excel - Comment.Parent property issue Office 2021
Novice
Exporting comments from word to excel - Comment.Parent property issue
 
Join Date: Oct 2023
Posts: 6
DuchessNora is on a distinguished road
Default

Quote:
Originally Posted by Italophile View Post
You need
Code:
StrCmt = StrCmt & vbTab & IIf(.Replies.Count = 0, "Not a Parent", "Is a Parent")
perfect, thank you!
Reply With Quote
  #5  
Old 10-25-2023, 01:14 AM
DuchessNora DuchessNora is offline Exporting comments from word to excel - Comment.Parent property issue Windows 11 Exporting comments from word to excel - Comment.Parent property issue Office 2021
Novice
Exporting comments from word to excel - Comment.Parent property issue
 
Join Date: Oct 2023
Posts: 6
DuchessNora is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
I think your logic is flawed. Having no replies doesn't mean the comment is a child-level comment. Instead you should be looking for presence of an Ancestor - top level comments don't have an ancestor. Then you can loop through any replies if they exist. Here is a snippet of code I'm currently using...
Code:
      For Each aCmt In wdDoc.Comments
        If aCmt.Ancestor Is Nothing Then        'a top level comment
           'do something
          If aCmt.Replies.Count > 0 Then
            For i = 1 To aCmt.Replies.Count
              Set aReply = aCmt.Replies(i)
              'do something with the replies
            Next i
          End If
        End If
      Next aCmt
I think the other code provided works for now, but if I use this one, where in the code do I need to place it? thank you
Reply With Quote
  #6  
Old 10-25-2023, 05:36 AM
Italophile Italophile is offline Exporting comments from word to excel - Comment.Parent property issue Windows 11 Exporting comments from word to excel - Comment.Parent property issue Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

You would replace
Code:
StrCmt = StrCmt & vbTab & IIf(.Parent Is Nothing, "Not a Parent", "Is a Parent")
with:
Code:
StrCmt = StrCmt & vbTab & IIf(.Ancestor Is Nothing, "Not a Parent", "Is a Parent")
Reply With Quote
  #7  
Old 11-07-2023, 05:50 AM
DuchessNora DuchessNora is offline Exporting comments from word to excel - Comment.Parent property issue Windows 11 Exporting comments from word to excel - Comment.Parent property issue Office 2021
Novice
Exporting comments from word to excel - Comment.Parent property issue
 
Join Date: Oct 2023
Posts: 6
DuchessNora is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
I think your logic is flawed. Having no replies doesn't mean the comment is a child-level comment. Instead you should be looking for presence of an Ancestor - top level comments don't have an ancestor. Then you can loop through any replies if they exist. Here is a snippet of code I'm currently using...
Code:
      For Each aCmt In wdDoc.Comments
        If aCmt.Ancestor Is Nothing Then        'a top level comment
           'do something
          If aCmt.Replies.Count > 0 Then
            For i = 1 To aCmt.Replies.Count
              Set aReply = aCmt.Replies(i)
              'do something with the replies
            Next i
          End If
        End If
      Next aCmt
Yes your right, I only just noticed when I used the other code it classed parents comments as not parents because they did not have any replies, I'll try changing it
Reply With Quote
  #8  
Old 11-07-2023, 05:57 AM
DuchessNora DuchessNora is offline Exporting comments from word to excel - Comment.Parent property issue Windows 11 Exporting comments from word to excel - Comment.Parent property issue Office 2021
Novice
Exporting comments from word to excel - Comment.Parent property issue
 
Join Date: Oct 2023
Posts: 6
DuchessNora is on a distinguished road
Default

Quote:
Originally Posted by Italophile View Post
You would replace
Code:
StrCmt = StrCmt & vbTab & IIf(.Parent Is Nothing, "Not a Parent", "Is a Parent")
with:
Code:
StrCmt = StrCmt & vbTab & IIf(.Ancestor Is Nothing, "Not a Parent", "Is a Parent")
Hi, I tried replacing this but it still classes the parent comment as not a parent? :/
Reply With Quote
  #9  
Old 11-07-2023, 05:59 AM
DuchessNora DuchessNora is offline Exporting comments from word to excel - Comment.Parent property issue Windows 11 Exporting comments from word to excel - Comment.Parent property issue Office 2021
Novice
Exporting comments from word to excel - Comment.Parent property issue
 
Join Date: Oct 2023
Posts: 6
DuchessNora is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
I think your logic is flawed. Having no replies doesn't mean the comment is a child-level comment. Instead you should be looking for presence of an Ancestor - top level comments don't have an ancestor. Then you can loop through any replies if they exist. Here is a snippet of code I'm currently using...
Code:
      For Each aCmt In wdDoc.Comments
        If aCmt.Ancestor Is Nothing Then        'a top level comment
           'do something
          If aCmt.Replies.Count > 0 Then
            For i = 1 To aCmt.Replies.Count
              Set aReply = aCmt.Replies(i)
              'do something with the replies
            Next i
          End If
        End If
      Next aCmt
where in my code do I place this, I tried copy and pasting into code but I get error messages
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parent/Child Comment Extract amschaefer Word VBA 1 10-19-2023 11:41 PM
[Reviving solved thread for additional help] Exporting Tracked Changes and Comments to Excel mjungli Word VBA 4 01-11-2023 09:39 AM
Exporting comments from word to excel - Comment.Parent property issue Exporting Tracked Changes and Comments to Excel alzasp Word VBA 14 06-14-2022 02:13 AM
How to hide comments and comment indicators from OTHERS Elena A Excel 0 12-03-2014 12:08 PM
Exporting comments from word to excel - Comment.Parent property issue Exporting Word Comments into a pdf blhowes Word 5 01-09-2010 12:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft