【问题标题】:When exporting Word review comments, how do you reference the sentence related to a comment?在导出 Word 审阅评论时,如何引用与评论相关的句子?
【发布时间】:2010-04-29 22:42:23
【问题描述】:

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

图片截图:http://jspeaks.com/mswordcomment.png

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

目前的逻辑是:

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,但是我无法确定包含引用语句的正确对象或属性。

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

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

【问题讨论】:

    标签: macros vbscript ms-word


    【解决方案1】:

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

    解决的关键是: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
    

    【讨论】:

    • 很高兴您有解决方案。您可以继续接受您自己的答案作为正确答案(复选标记)。
    【解决方案2】:

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

    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
    

    来自Microsoft Answers的最有价值的帮助

    【讨论】:

    • user662182:感谢您的出色贡献,但在用户按照 VBA 源的 TODO 注释中的说明进行操作之前,此宏不会在 Word 2007 下编译。需要注意的是,如果用户不执行此操作就执行,Tools->References 选项将灰显... RESET the current macro in the VB Editor, THEN option is active!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 2011-07-24
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多