导出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,但是我无法确定包含引用句子的正确对象或属性。
我想产生如下输出(如果我们使用上图中的示例):
句子:这里有更多包含有趣事实的句子 - 评论:这是一个有趣的事实。 句子:这里有更多包含有趣事实的句子。这里有更多包含有趣事实的句子。 - 评论:这是一个非常有趣的事实
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在另一个网站上找到了有人来解决这个问题。
解决的关键是: cmt.Scope.FormattedText
这里是修改后的函数:
I found someone on another site to solve this question.
The key to the solution is: cmt.Scope.FormattedText
Here is the function revised:
我收集了几段代码并得出了这个解决方案:
来自 微软答复
I have gathered several pieces of code and came to this solution:
Most valuable help from Microsoft Answers
如果要包含与注释相关的突出显示的参考文本,请添加以下代码行以及类似的其他代码行:
.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!