Вызов свойства Comment.Replies (Word) для настройки CopyCommentsToExcel () - PullRequest
0 голосов
/ 26 апреля 2019

Нужно получать комментарии и ответы на комментарии из слова, используя VBA для превосходства, с любыми дочерними ответами на родительский комментарий в той же ячейке Excel.

В настоящее время используется проверенный и верный метод, но требуется помощь при вызове объекта ответов, чтобы вставить их в ту же ячейку.Рассматриваемый документ - это сотни страниц с тысячами комментариев / ответов, поэтому предпочитайте делать это в VBA verus после факта с помощью формул Excel.

For i = 1 To ActiveDocument.Comments.Count
    .Cells(2, 1).Formula = ActiveDocument.Comments(i).Parent
    .Cells(i + HeadingRow, 1).Formula = ActiveDocument.Comments(i).Index
    .Cells(i + HeadingRow, 2).Formula = ActiveDocument.Comments(i).Reference.Information(wdActiveEndAdjustedPageNumber)
    .Cells(i + HeadingRow, 3).Formula = ActiveDocument.Comments(i).Reference.Information(wdFirstCharacterLineNumber)
    .Cells(i + HeadingRow, 4).Formula = ActiveDocument.Comments(i).Range
    .Cells(i + HeadingRow, 5).Formula = ActiveDocument.Comments(i).Initial
    .Cells(i + HeadingRow, 6).Formula = Format(ActiveDocument.Comments(i).Date, "dd/MM/yyyy")
    '        .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Parent
    '        .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Application
    '        .Cells(i + 1, 7).Formula = ActiveDocument.Comments(i).Author

Как написано выше, я не могу планировать / визуализироватькак объединить .Parent и .Child в одну ячейку, а затем перейти к следующей.

1 Ответ

0 голосов
/ 26 апреля 2019

Добавьте модуль в ваш проект в Word VBE и добавьте в него приведенный ниже UDF:

Function GetComments() As Scripting.Dictionary
    Dim oComms As Comments: Set oComms = ThisDocument.Comments
    Dim iComm As Long
    Dim dComs As Scripting.Dictionary: Set dComs = New Scripting.Dictionary     '<-- Requires reference to 'Microsoft Scripting Runtime'
    Dim sParentText As String

    ' Loop to go through all comments in current document
    For iComm = 1 To oComms.Count

        ' Get the parent text
        sParentText = oComms.Item(iComm).Scope.Text

        ' Check if dictionary already has a key with parent text
        If dComs.Exists(sParentText) Then
            ' Key exists so add current comment at the end
            dComs(sParentText) = dComs(sParentText) & vbCrLf & oComms.Item(iComm).Range.Text
        Else
            ' Key doesnt exist so create a new key
            dComs.Add sParentText, oComms.Item(iComm).Range.Text
        End If

    Next

    ' Set return value
    Set GetComments = dComs

End Function

Теперь вы можете вызывать вышеуказанный UDF следующим образом:

Sub TestComments()
    Dim dComs As Scripting.Dictionary
    Dim oKey As Variant

    ' Call UDF to get all comments from current doc
    Set dComs = GetComments

    ' Loop just to show the comments (NOT need at runtime)
    For Each oKey In dComs.Keys
        MsgBox dComs(oKey)
    Next

End Sub

GetComments возвращает словарь всех комментариев в документе с ответами, перечисленными в новой строке в том же ключе. Вы можете добавить их в ячейки в Excel

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...