2010-04-29 66 views
4

我正试图导出Word文档的评论评论。我想导出评论后的评论句子选择。图像的导出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修修补补,但是我不能确定包含被引用的句子正确的对象或属性。

我想产生这样(如果我们使用的例子在上面图片)输出:

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

回答

8

我发现有人在另一个网站上解决这个问题。

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

很好,你有一个解决方案。你可以继续,并接受你自己的答案作为正确答案(复选标记)。 – 2010-06-27 15:49:32

3

我已经收集几件代码,并来到这个解决方案:

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

+0

user662182: 感谢您的出色贡献,但是此宏不会在Word 2007下编译,直到用户 按照VBA源代码的TODO注释中的说明操作。 重要的是要注意,如果用户没有这样做,工具 - >引用选项将灰显出来......重置VB编辑器中的当前宏,那么该选项是活动的! – user2831074 2014-12-17 14:44:09