如何使用页面和注释创建新的word文档?

时间:2014-03-31 21:02:11

标签: vba ms-word

我想使用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

1 个答案:

答案 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