我有一份文件,上面有一份很长的采访记录。我found a Macro on SO,让我导出这些评论与突出显示的文本。这很棒,但是输出非常枯燥(纯文本)。
我需要知道是否以及如何应用粗体、斜体和插入换行符。我已经找了大约一个小时了,因为我的VBA很糟糕,除了在"marco output formatting“上搜索关键字之外,我没有其他参考。
有人知道如何将以下脚本和字体更改为文本的一部分吗?
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
也许我可以用文字解释的HTML来做呢?
发布于 2013-05-07 14:45:53
我假设您希望包含的格式已经包含在注释文本中,并且您只是在寻找一种将其写入最终文档的方法。下面是您的脚本的一个修改版本,可以这样做(下面列出了一个警告):
Sub ExportComments()
Dim cmt As Comment
Dim newdoc As Document
Dim currDoc As Document
Set currDoc = ActiveDocument
Set newdoc = Documents.Add
currDoc.Activate
For Each cmt In currDoc.Comments
With newdoc.Content
cmt.Scope.Copy
.InsertAfter "Text: "
.Collapse wdCollapseEnd
.Paste
.InsertAfter " - > "
cmt.Range.Copy
.InsertAfter "Comments: " & cmt.Initial & cmt.Index & ":"
.Collapse wdCollapseEnd
.Paste
.InsertParagraphAfter
End With
Next
End Sub
这里的不同之处在于,我使用的是复制和粘贴,而不是生成文本字符串。
注意:在当前编写宏时,范围(显示在文件文本旁边的文本)中的任何字符格式都将应用于箭头和首字母。这很容易通过搜索和替换来修复,所以我没有将它合并到脚本中。
https://stackoverflow.com/questions/16369638
复制相似问题