我正在尝试导出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进行了修补,但是我无法确定包含被引用句子的适当对象或属性。
我想生成如下输出(如果我们使用上图中的示例):
句子:这里有更多包含有趣事实的句子-注释:这是一个有趣的事实。句子:这里有更多包含有趣事实的句子。这里有更多包含有趣事实的句子。-评论:这是一个非常有趣的事实
发布于 2010-05-14 21:06:30
我在另一个网站上找到了解决这个问题的人。
解决方案的关键是: 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发布于 2011-12-20 20:22:13
我收集了几段代码,得出了以下解决方案:
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的最有价值帮助
https://stackoverflow.com/questions/2741241
复制相似问题