Extract Comments Macros for Word 2011

Discussion in 'Mac Apps and Mac App Store' started by rjleamaster, Jan 26, 2012.

  1. rjleamaster macrumors newbie

    Joined:
    Jan 26, 2012
    #1
    I have found a macros for older versions of Word that will extract comments from a document and create a table in a new document with 4 columns.
    Column 1: page number of comment
    Column 2: the commented text
    Column 3: the actual comment
    Column 4: the person commenting

    I have pasted the macros below, but I can't get it to work in Word 2011. I colored the problematic text in red (or at least part of the problem). Anyone out there know how to get this to work? Or maybe have different code altogether? I haven't the slightest. Thanks ahead of time for your help.


    Attribute VB_Name = "basComments_Extract"
    Option Explicit

    Public Sub ExtractCommentsToNewDoc()

    'Macro created 2007 by Lene Fredborg, DocTools - www.thedoctools.com
    'The macro creates a new document
    'and extracts all comments from the active document
    'incl. metadata

    'Minor adjustments are made to the styles used
    'You may need to change the style settings and table layout to fit your needs
    '=========================

    Dim oDoc As Document
    Dim oNewDoc As Document
    Dim oTable As Table
    Dim nCount As Long
    Dim n As Long
    Dim Title As String

    Title = "Extract All Comments to New Document"
    Set oDoc = ActiveDocument
    nCount = ActiveDocument.Comments.Count

    If nCount = 0 Then
    MsgBox "The active document contains no comments.", vbOKOnly, Title
    GoTo ExitHere
    Else
    'Stop if user does not click Yes
    If MsgBox("Do you want to extract all comments to a new document?", _
    vbYesNo + vbQuestion, Title) <> vbYes Then
    GoTo ExitHere
    End If
    End If

    Application.ScreenUpdating = False
    'Create a new document for the comments, base on Normal.dot
    Set oNewDoc = Documents.Add
    'Set to landscape
    oNewDoc.PageSetup.Orientation = wdOrientLandscape
    'Insert a 4-column table for the comments
    With oNewDoc
    .Content = ""
    Set oTable = .Tables.Add _
    (Range:=Selection.Range, _
    numrows:=nCount + 1, _
    NumColumns:=4)
    End With

    'Insert info in header - change date format as you wish
    oNewDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = _
    "Comments extracted from: " & oDoc.FullName & vbCr & _
    "Created by: " & Application.UserName & vbCr & _
    "Creation date: " & Format(Date, "MMMM d, yyyy")

    'Adjust the Normal style and Header style
    With oNewDoc.Styles(wdStyleNormal)
    .Font.Name = "Arial"
    .Font.Size = 10
    .ParagraphFormat.LeftIndent = 0
    .ParagraphFormat.SpaceAfter = 6
    End With

    With oNewDoc.Styles(wdStyleHeader)
    .Font.Size = 8
    .ParagraphFormat.SpaceAfter = 0
    End With

    'Format the table appropriately
    With oTable
    .Range.Style = wdStyleNormal
    .AllowAutoFit = False
    .PreferredWidthType = wdPreferredWidthPercent
    .PreferredWidth = 100
    .Columns(1).PreferredWidth = 5
    .Columns(2).PreferredWidth = 25
    .Columns(3).PreferredWidth = 50
    .Columns(4).PreferredWidth = 20
    .Rows(1).HeadingFormat = True
    End With

    'Insert table headings
    With oTable.Rows(1)
    .Range.Font.Bold = True
    .Cells(1).Range.Text = "Page"
    .Cells(2).Range.Text = "Comment scope"
    .Cells(3).Range.Text = "Comment text"
    .Cells(4).Range.Text = "Author"
    End With

    'Get info from each comment from oDoc and insert in table
    For n = 1 To nCount
    With oTable.Rows(n + 1)
    'Page number
    .Cells(1).Range.Text = _
    oDoc.Comments(n).Scope.Information(wdActiveEndPageNumber)
    'The text marked by the comment
    .Cells(2).Range.Text = oDoc.Comments(n).Scope
    'The comment itself
    .Cells(3).Range.Text = oDoc.Comments(n).Range.Text
    'The comment author
    .Cells(4).Range.Text = oDoc.Comments(n).Author
    End With
    Next n

    Application.ScreenUpdating = True
    Application.ScreenRefresh

    oNewDoc.Activate
    MsgBox nCount & " comments found. Finished creating comments document.", vbOKOnly, Title

    ExitHere:
    Set oDoc = Nothing
    Set oNewDoc = Nothing
    Set oTable = Nothing

    End Sub
     
  2. Hawkeye16, Jan 26, 2012
    Last edited: Jan 26, 2012

    Hawkeye16 macrumors regular

    Joined:
    Sep 16, 2009
    Location:
    Iowa
    #2
    It works for me in Word 2011 on my Mac... The part you have in red is only used in the title of the 2 message boxes so you could technically take it out or change it to whatever you want.
     

    Attached Files:

  3. rjleamaster thread starter macrumors newbie

    Joined:
    Jan 26, 2012
    #3
    Got it working too

    I now have it working too. Thanks for the response. I found another macros that is great for writers who like to work with plain text, but have collaborators who insist on using Word. It extracts the comments and puts them in brackets after the commented text. It might be useful to others viewing this thread:

    Sub PrintCommentsWithText()
    Dim c As Comment
    For Each c In ActiveDocument.Comments c.Reference.InsertAfter "[" & c.Range.Text & "]"
    Next c End Sub
     
  4. tbell macrumors newbie

    Joined:
    Jun 25, 2009
    #4
    How exactly do you paste macro code like this in Word 2011 to get it working? I have some code I want to use but don't know what to do with it because I'm a macro n00b. The code I have is for printing only pages with track changes.

    Just FYI it is:

    Dim revpage As Long, pageprint As String
    pageprint = 0
    With ActiveDocument
    For i = 1 To .Revisions.Count
    .Revisions(i).Range.Select
    Selection.Collapse wdCollapseStart
    revpage = Selection******rmation(wdActiveEndPageNumber)
    If revpage > pageprint Then
    pageprint = revpage
    Else
    GoTo Skip
    End If
    MsgBox pageprint
    .PrintOut Range:=wdPrintRangeOfPages, Copies:=1, Pages:=pageprint
    Skip:
    Next i
    End With

    -----------
    Thanks!
     

Share This Page