我想使用VBA创建一个新文档,其中包含带有文档注释的页面。我只发现这个宏创建了一个仅列出注释的文档。我需要带有评论的页面。如何修改?提前谢谢!
Sub PrintOnlyComments()
Dim oThisDoc As Document
Dim oThatDoc As Document
Dim c As Comment
Dim sTemp As String
Dim iPage As Integer
Set oThisDoc = ActiveDocument
Set oThatDoc = Documents.Add
Application.ScreenUpdating = False
For Each c In oThisDoc.Comments
'Find page number of comment
oThisDoc.Select
c.Reference.Select
iPage = Selection.Information(wdActiveEndAdjustedPageNumber)
'Put info in new document
oThatDoc.Select
Selection.EndKey Unit:=wdStory
sTemp = "Page: " & iPage
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
sTemp = "[" & c.Initial & c.Index & "] " & c.Range
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
Next
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
我明白了。如果有人有兴趣,这是我的计划:
Sub PrintOnlyComments()
Dim oThisDoc As Document
Dim oThatDoc As Document
Dim c As Comment
Dim sTemp As String
Dim iPage As Integer
Dim iPage0 As Integer
Set oThisDoc = ActiveDocument
Set oThatDoc = Documents.Add
iPage0 = 0
Application.ScreenUpdating = False
For Each c In oThisDoc.Comments
'Find page number of comment
oThisDoc.Select
c.Reference.Select
iPage = Selection.Information(wdActiveEndAdjustedPageNumber)
'paste the page to a new document
If iPage <> iPage0 Then
Selection.GoTo wdGoToPage, wdGoToAbsolute, iPage
Selection.Bookmarks("\Page").Range.Copy
oThatDoc.Activate
Selection.PageSetup.Orientation = wdOrientLandscape
Selection.EndKey
Selection.Paste
End If
iPage0 = iPage
Next
Application.ScreenUpdating = True
End Sub