导出Word审稿评论时,如何引用与评论相关的句子?

发布于 2024-08-30 19:36:00 字数 735 浏览 2 评论 0原文

我正在尝试导出Word文档的审阅评论。我想导出评论后的句子选择。

图像的屏幕截图: http://jspeaks.com/mswordcomment.png

我找到了代码循环浏览文档评论,但我不知道如何引用与评论相关的句子选择。

当前的逻辑是:

Sub ExportComments()
    Dim s As String
    Dim cmt As Word.Comment
    Dim doc As Word.Document

    For Each cmt In ActiveDocument.Comments
        s = s & cmt.Initial & cmt.Index & "," & cmt.Range.Text & vbCr
    Next

    Set doc = Documents.Add
    doc.Range.Text = s
End Sub

我修改了 Selection.Range,但是我无法确定包含引用句子的正确对象或属性。

我想产生如下输出(如果我们使用上图中的示例):

句子:这里有更多包含有趣事实的句子 - 评论:这是一个有趣的事实。 句子:这里有更多包含有趣事实的句子。这里有更多包含有趣事实的句子。 - 评论:这是一个非常有趣的事实

I am trying to export a Word document's review comments. I want to export the sentence selection that was commented on followed by the comment.

Screen shot of the image: http://jspeaks.com/mswordcomment.png

I have found code to loop through the document comments, but I cannot figure out how to reference the sentence selection that the comment was related to.

The current logic is:

Sub ExportComments()
    Dim s As String
    Dim cmt As Word.Comment
    Dim doc As Word.Document

    For Each cmt In ActiveDocument.Comments
        s = s & cmt.Initial & cmt.Index & "," & cmt.Range.Text & vbCr
    Next

    Set doc = Documents.Add
    doc.Range.Text = s
End Sub

I tinkered with Selection.Range, however I cannot determine the proper object or property that contains the referenced sentence.

I would like to produce output like the following (if we use the example in picture above):

Sentence: Here are more sentences that contain interesting facts - Comment: This is an interesting fact.
Sentence: Here are more sentences that contain interesting facts. Here are more sentences that contain interesting facts. - Comment: This is a very interesting fact

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青瓷清茶倾城歌 2024-09-06 19:36:00

我在另一个网站上找到了有人来解决这个问题。

解决的关键是: cmt.Scope.FormattedText

这里是修改后的函数:

Sub ExportComments()
    Dim s As String
    Dim cmt As Word.Comment
    Dim doc As Word.Document

    For Each cmt In ActiveDocument.Comments
        s = s & "Text: " & cmt.Scope.FormattedText & " -> "
        s = s & "Comments: " & cmt.Initial & cmt.Index & ":" & cmt.Range.Text & vbCr
    Next

    Set doc = Documents.Add
    doc.Range.Text = s
End Sub

I found someone on another site to solve this question.

The key to the solution is: cmt.Scope.FormattedText

Here is the function revised:

Sub ExportComments()
    Dim s As String
    Dim cmt As Word.Comment
    Dim doc As Word.Document

    For Each cmt In ActiveDocument.Comments
        s = s & "Text: " & cmt.Scope.FormattedText & " -> "
        s = s & "Comments: " & cmt.Initial & cmt.Index & ":" & cmt.Range.Text & vbCr
    Next

    Set doc = Documents.Add
    doc.Range.Text = s
End Sub
ペ泪落弦音 2024-09-06 19:36:00

我收集了几段代码并得出了这个解决方案:

Sub CopyCommentsToExcel()
'Create in Word vba
'TODO: set a reference to the Excel object library (Tools --> Reference --> Microsoft Excel 12.0 Object library)

Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim i As Integer
Dim HeadingRow As Integer
HeadingRow = 3

Dim cmtRef As Range

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add ' create a new workbook
With xlWB.Worksheets(1)
' Create report info
    .Cells(1, 1).Formula = "Reviewed document:"

' Create Heading
    .Cells(HeadingRow, 1).Formula = "Index"
    .Cells(HeadingRow, 2).Formula = "Page"
    .Cells(HeadingRow, 3).Formula = "Line"
    .Cells(HeadingRow, 4).Formula = "Comment"
    .Cells(HeadingRow, 5).Formula = "Reviewer"
    .Cells(HeadingRow, 6).Formula = "Date"
    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
    Next i
End With
Set xlWB = Nothing
Set xlApp = Nothing
End Sub

来自 微软答复

I have gathered several pieces of code and came to this solution:

Sub CopyCommentsToExcel()
'Create in Word vba
'TODO: set a reference to the Excel object library (Tools --> Reference --> Microsoft Excel 12.0 Object library)

Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim i As Integer
Dim HeadingRow As Integer
HeadingRow = 3

Dim cmtRef As Range

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add ' create a new workbook
With xlWB.Worksheets(1)
' Create report info
    .Cells(1, 1).Formula = "Reviewed document:"

' Create Heading
    .Cells(HeadingRow, 1).Formula = "Index"
    .Cells(HeadingRow, 2).Formula = "Page"
    .Cells(HeadingRow, 3).Formula = "Line"
    .Cells(HeadingRow, 4).Formula = "Comment"
    .Cells(HeadingRow, 5).Formula = "Reviewer"
    .Cells(HeadingRow, 6).Formula = "Date"
    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
    Next i
End With
Set xlWB = Nothing
Set xlApp = Nothing
End Sub

Most valuable help from Microsoft Answers

跨年 2024-09-06 19:36:00

如果要包含与注释相关的突出显示的参考文本,请添加以下代码行以及类似的其他代码行:

.Cells(HeadingRow, 7).Formula = "Reference text"
.Cells(i + HeadingRow, 7).Formula = ActiveDocument.Comments(i).Scope

另外,我必须注释掉以下代码行,也许是因为 Excel 已打开(不确定)
'将 xlApp 调暗为 Excel.Application
'Dim xlWB As Excel.Workbook

否则,上面的程序就像一个魅力。谢谢!

If you want to include the highlighted reference text that a comment relates to, add these lines of code with others like them:

.Cells(HeadingRow, 7).Formula = "Reference text"
.Cells(i + HeadingRow, 7).Formula = ActiveDocument.Comments(i).Scope

Also, I had to comment out the following lines of code, perhaps because Excel was open (not sure)
'Dim xlApp As Excel.Application
'Dim xlWB As Excel.Workbook

Otherwise, the program above worked like a charm. Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文