Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 33 of 33

Thread: Comment extraction - to include sections as well as page numbers

  1. #21
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    So this intrigued me, and it doesn't appear that there is any built-in functionality for this. I often am surprised when something which seems rather logical and straightforward doesn't exist (such as having a property of a document which is built-in list of paragraphs and their outline levels, similar to the way the XRef list is built on the fly). But there isn't, in this case, that I can discover.

    So here are two alternative methods for the price of one One is simple, and uses brute force. It simply goes backward, paragraph by paragraph, until it finds a style name which matches the select case list. And then it returns the text of that paragraph, minus the paragraph mark.

    The other is much more complex, conceptually. If you are a beginner, this may not be the one to use unless you find the simple one seems slow. There is a lot of stuff going on which may be a little overwhelming to understand. But this is the way I would do it, because using the Find object to, well, find things is *always* faster

    Conceptually, the complex method uses a series of Find operations to build a collection of found ranges, and then tests those found ranges against the original range to check distance, and thus determine, among the found ranges, which is closest-- and thus return that text.

    In all cases, although it is much more code, it would be faster. Depending on how your document is constructed, it *could* be significantly faster (if your original document with the comments has a lot of tables, looping through each paragraph can be really really slow). But it's also, as I said, considerably more complex. So, use at your own risk

    And lastly... you would use these at the same place I said before... in your With...End With block, by doing either
    'simple method
    .Cells(3).Range.Text = fGetParaTextBefore(oDoc.Comments(n).Scope)
    'complex method
    .Cells(3).Range.Text = fGetNearestParaTextStyledIn(oDoc.Comments(n).Scope)

    Here you go... good luck.

    - Frosty
    [vba]
    '----------------------------------------------------------------------------------------------------------
    ' SIMPLE METHOD:
    ' A simpler to understand method, but uses brute force, and thus may become slow on larger documents
    '----------------------------------------------------------------------------------------------------------
    Public Function fGetParaTextBefore(rngBefore As Range)
    Dim oPara As Paragraph
    Dim sReturn As String

    On Error GoTo l_err
    Set oPara = rngBefore.Paragraphs(1)
    'go back, paragraph by paragraph...
    Do Until oPara.Previous Is Nothing

    Set oPara = oPara.Previous
    Select Case oPara.Style
    Case "Heading 1", "Heading 2", "Heading 3"
    'we found one with the right style
    Exit Do
    Case Else
    'keep looking!
    End Select
    'make sure we don't reach the top of the document
    Loop

    'get the text
    sReturn = oPara.Range.Text

    'and you probably don't want the paragraph mark
    sReturn = Replace(sReturn, vbCr, "")

    l_exit:
    fGetParaTextBefore = sReturn
    Exit Function
    l_err:
    sReturn = ""
    Resume l_exit
    End Function
    '----------------------------------------------------------------------------------------------------------
    ' COMPLEX METHOD:
    ' Uses the Find object (which is always faster) to search an array of style names
    ' and return the text of the paragraph nearest to the original range
    '----------------------------------------------------------------------------------------------------------
    Public Function fGetNearestParaTextStyledIn(Optional rngOriginal As Range, _
    Optional sStyleNames As String = "Heading 1|Heading 2|Heading 3", _
    Optional bLookDown As Boolean = False, _
    Optional bIncludeParagraphMark As Boolean = False) As String

    Dim oDoc As Document
    Dim aryStyleNames() As String
    Dim colFoundRanges As Collection
    Dim rngReturn As Range
    Dim i As Integer
    Dim sReturnText As String
    Dim lDistance As Long

    On Error GoTo l_err
    'set a default if we didn't pass it
    If rngOriginal Is Nothing Then
    Set rngOriginal = Selection.Range.Duplicate
    End If

    'create a new instance of a collection
    Set colFoundRanges = New Collection

    'get our array of style names to look for
    aryStyleNames = Split(sStyleNames, "|")

    'loop through the array
    For i = 0 To UBound(aryStyleNames)
    'if you wanted to add additional styles, you could change the optional parameter, or
    'pass in different values
    Set rngReturn = fGetNearestParaRange(rngOriginal.Duplicate, aryStyleNames(i), bLookDown)
    'if we found it in the search direction
    If Not rngReturn Is Nothing Then
    'then add it to the collection
    colFoundRanges.Add rngReturn
    End If
    Next

    'if we found anything in our collection, then we can go through it,
    'and see which range is closest to our original range, depending on our search direction
    If colFoundRanges.Count > 0 Then
    'start with an initial return
    Set rngReturn = colFoundRanges(1)
    'and an initial distance value as an absolute number
    lDistance = Abs(rngOriginal.Start - rngReturn.Start)
    'then go through the rest of them, and return the one with the lowest distance between
    For i = 2 To colFoundRanges.Count
    If lDistance > Abs(rngOriginal.Start - colFoundRanges(i).Start) Then
    'set a new range
    Set rngReturn = colFoundRanges(i)
    'and a new distance test
    lDistance = Abs(rngOriginal.Start - rngReturn.Start)
    End If
    Next

    'now get the text we're going to return
    sReturnText = rngReturn.Text
    'and whether to include the paragraph mark
    If bIncludeParagraphMark = False Then
    sReturnText = Replace(sReturnText, vbCr, "")
    End If
    End If


    l_exit:
    fGetNearestParaTextStyledIn = sReturnText
    Exit Function
    l_err:
    'black box, so that any errors return an empty string
    sReturnText = ""
    Resume l_exit
    End Function
    '----------------------------------------------------------------------------------------------------------
    'return the nearest paragraph range styled
    'defaults to Heading 1
    'NOTE: if searching forward, starts searching from the *beginning* of the passed range
    ' if searching backward, starts searching from the *end* of the passed range
    '----------------------------------------------------------------------------------------------------------
    Public Function fGetNearestParaRange(rngWhere As Range, _
    Optional sStyleName As String = "Heading 1", _
    Optional bSearchForward As Boolean = False) As Range
    Dim rngSearch As Range

    On Error GoTo l_err
    Set rngSearch = rngWhere.Duplicate
    'if searching down, then start at the beginning of our search range
    If bSearchForward Then
    rngSearch.Collapse wdCollapseStart
    'otherwise, search from the end
    Else
    rngSearch.Collapse wdCollapseEnd
    End If

    'find the range
    With rngSearch.Find
    .Wrap = wdFindStop
    .Forward = bSearchForward
    .Style = sStyleName
    'if we found it, return it
    If .Execute Then
    Set fGetNearestParaRange = rngSearch
    Else
    Set fGetNearestParaRange = Nothing
    End If
    End With

    l_exit:
    Exit Function
    l_err:
    'black box- any errors, return nothing
    Set rngSearch = Nothing
    Resume l_exit
    End Function
    [/vba]

  2. #22
    VBAX Regular
    Joined
    May 2012
    Posts
    18
    Location
    You sound like me yesterday - it must be possible, surely they wouldnt

    Many thanks, that code works great and I think I can follow most of it.

    Phil

  3. #23
    VBAX Regular
    Joined
    May 2012
    Posts
    18
    Location
    Hi Frosty

    So that code works great, but I've just encountered another formatted document type which is also used and while the code extracts the heading of the subsection, they have essentially created a list style and then linked the list style to the various headings, so they get a numbered approach 1, 1.1 etc.

    Is it possible to extract the numbers for each part of the document as well?

    I have attached a new sample document to illustrate the point

    I've got to review a bunch of docs today so will work on it over the weekend, but I thought I would be cheeky and ask in case you said oh yes just change X to Y in the code.
    Attached Files Attached Files

  4. #24
    VBAX Regular
    Joined
    May 2012
    Posts
    18
    Location
    I was reading your code and hoped it was returned by setting bincludeparagrah mark to true, but it isn't unless I need to add a piece of text onto SReturnText.

    I am looking at http://msdn.microsoft.com/en-us/libr...nge_properties to see if there is a property which we would have found with the recursive search in the document, but its slow going trying them out and reading them as well to be honest - sometimes hyperlinked documents don't rule

    I'm going to have a play with it all and any answer post back here

  5. #25
    VBAX Regular
    Joined
    May 2012
    Posts
    18
    Location
    That was quick and easy

    Simply use the .ListFormat.ListString part of the range and then you can concatenate the two together and return section numbering and section title

    Thanks to this page for answer

    http://word.mvps.org/faqs/numbering/liststring.htm

    Frosty still rules for the search code though

  6. #26
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Umm... Yes. ListString and prepending it on to the return string is the way to go glad to be of service!

    Also, since others can benefit from your discoveries, it's nice to post the lines of code you modified to get what you wanted, rather than just the links to the research. That way everyone benefits... Including you, if you made a mistake with your modification.

    I'm glad you figured it out on your own, that's fantastic.

  7. #27
    VBAX Regular
    Joined
    May 2012
    Posts
    18
    Location
    Finished Code

    [vba] Public Sub ExtractCommentsToNewDoc()

    'Original source Macro created 2007 by Lene Fredborg, DocTools
    'amended by Phil Thomas May 2012 www.grosvenorsc.com
    'with help from Frosty at VBAExpress.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
    '=========================
    'Setup all the variables
    Dim oDoc As Document
    Dim oNewDoc As Document
    Dim oTable As Table
    Dim nCount As Long
    Dim n As Long
    Dim Title As String

    'Setup intital values
    Title = "Extract All Comments to New Document"
    Set oDoc = ActiveDocument
    nCount = ActiveDocument.Comments.Count

    'Check if document has any comments in it and if it does, then check this is what the user wants to do
    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

    'Turned on as recommendation from MSDN Technet article
    Application.ScreenUpdating = True
    'Create a new document for the comments, based on Normal.dot
    Set oNewDoc = Documents.Add
    'Set to landscape
    oNewDoc.PageSetup.Orientation = wdOrientLandscape
    'Insert a 10-column table for the comments
    With oNewDoc
    .Content = ""
    Set oTable = .Tables.Add _
    (Range:=Selection.Range, _
    NumRows:=nCount + 1, _
    NumColumns:=9)
    End With

    'Insert info in header - change date format as you wish
    oNewDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = _
    "Document Review Record - " & "Comments extracted from: " & oDoc.Name & vbCr & _
    "Created by: " & Application.UserName & _
    " Creation date: " & Format(Date, "MMMM d, yyyy") & _
    " - All page and line numbers are with Final: Show Markup turned on"
    'insert page number into footer
    oNewDoc.Sections(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add PageNumberAlignment:=wdAlignPageNumberRight


    'Adjust the Normal style and Header style
    With oNewDoc.Styles(wdStyleNormal)
    .Font.Name = "Arial"
    .Font.Size = 8
    .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
    .AllowAutoFit = False
    .Style = "Table Grid"
    .PreferredWidthType = wdPreferredWidthPercent
    .PreferredWidth = 100
    .Columns(1).PreferredWidth = 5
    .Columns(2).PreferredWidth = 20
    .Columns(3).PreferredWidth = 5
    .Columns(4).PreferredWidth = 5
    .Columns(5).PreferredWidth = 20
    .Columns(6).PreferredWidth = 20
    .Columns(7).PreferredWidth = 10
    .Columns(8).PreferredWidth = 15
    .Columns(8).Shading.BackgroundPatternColor = -570359809
    .Columns(9).PreferredWidth = 20
    .Columns(9).Shading.BackgroundPatternColor = -570359809
    .Rows(1).HeadingFormat = True
    End With

    'Insert table headings
    With oTable.Rows(1)
    .Range.Font.Bold = True
    .Shading.BackgroundPatternColor = 5296274
    .Cells(1).Range.Text = "Comment"
    .Cells(2).Range.Text = "Section Heading"
    .Cells(3).Range.Text = "Page"
    .Cells(4).Range.Text = "Line on Page"
    .Cells(5).Range.Text = "Comment scope"
    .Cells(6).Range.Text = "Comment text"
    .Cells(7).Range.Text = "Author"
    .Cells(8).Range.Text = "Response Summary (Accept/ Reject/ Defer)"
    .Cells(9).Range.Text = "Response to comment"
    End With

    'Repaginate - Start MSDN bug fix on Knowledgebase article
    ActiveDocument.Repaginate

    'Toggle nonprinting characters twice
    ActiveWindow.ActivePane.View.ShowAll = Not _
    ActiveWindow.ActivePane.View.ShowAll

    ActiveWindow.ActivePane.View.ShowAll = Not _
    ActiveWindow.ActivePane.View.ShowAll
    'End MSDN KB code


    'Get info from each comment from oDoc and insert in table, no way to currently insert Criticality of comment.
    'Suggest either done afterwards or simply include C,S,M in the start of each comment and remove Col 8
    For n = 1 To nCount
    With oTable.Rows(n + 1)
    .Cells(1).Range.Text = n
    'call function to get section heading
    .Cells(2).Range.Text = fGetNearestParaTextStyledIn(oDoc.Comments(n).Scope)
    'Page number
    .Cells(3).Range.Text = oDoc.Comments(n).Scope.Information(wdActiveEndPageNumber)
    ' The line number
    .Cells(4).Range.Text = oDoc.Comments(n).Scope.Information(wdFirstCharacterLineNumber)
    'The text marked by the comment
    .Cells(5).Range.Text = oDoc.Comments(n).Scope
    'The comment itself
    .Cells(6).Range.Text = oDoc.Comments(n).Range.Text
    'The comment author
    .Cells(7).Range.Text = oDoc.Comments(n).Author
    End With
    Next n

    Application.ScreenUpdating = True
    Application.ScreenRefresh

    'Tell them its finished
    oNewDoc.Activate
    MsgBox nCount & " comments found. Finished creating comments document.", vbOKOnly, Title

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

    End Sub


    '----------------------------------------------------------------------------------------------------------
    ' COMPLEX SEARCH METHOD:
    ' Uses the Find object (which is always faster) to search an array of style names
    ' and return the text of the paragraph nearest to the original range
    '----------------------------------------------------------------------------------------------------------
    Public Function fGetNearestParaTextStyledIn(Optional rngOriginal As Range, _
    Optional sStyleNames As String = "Heading 1|Heading 2|Heading 3", _
    Optional bLookDown As Boolean = False, _
    Optional bIncludeParagraphMark As Boolean = False) As String

    Dim oDoc As Document
    Dim aryStyleNames() As String
    Dim colFoundRanges As Collection
    Dim rngReturn As Range
    Dim i As Integer
    Dim sReturnText As String
    Dim s1ReturnText As String
    Dim s2ReturnText As String
    Dim lDistance As Long

    On Error GoTo l_err
    'set a default if we didn't pass it
    If rngOriginal Is Nothing Then
    Set rngOriginal = Selection.Range.Duplicate
    End If

    'create a new instance of a collection
    Set colFoundRanges = New Collection

    'get our array of style names to look for
    aryStyleNames = Split(sStyleNames, "|")

    'loop through the array
    For i = 0 To UBound(aryStyleNames)
    'if you wanted to add additional styles, you could change the optional parameter, or
    'pass in different values
    Set rngReturn = fGetNearestParaRange(rngOriginal.Duplicate, aryStyleNames(i), bLookDown)
    'if we found it in the search direction
    If Not rngReturn Is Nothing Then
    'then add it to the collection
    colFoundRanges.Add rngReturn
    End If
    Next

    'if we found anything in our collection, then we can go through it,
    'and see which range is closest to our original range, depending on our search direction
    If colFoundRanges.Count > 0 Then
    'start with an initial return
    Set rngReturn = colFoundRanges(1)
    'and an initial distance value as an absolute number
    lDistance = Abs(rngOriginal.Start - rngReturn.Start)
    'then go through the rest of them, and return the one with the lowest distance between
    For i = 2 To colFoundRanges.Count
    If lDistance > Abs(rngOriginal.Start - colFoundRanges(i).Start) Then
    'set a new range
    Set rngReturn = colFoundRanges(i)
    'and a new distance test
    lDistance = Abs(rngOriginal.Start - rngReturn.Start)
    End If
    Next

    'now get the text we're going to return
    s1ReturnText = rngReturn.ListFormat.ListString
    s2ReturnText = rngReturn.Text
    sReturnText = s1ReturnText & " - " & s2ReturnText
    'and whether to include the paragraph mark
    If bIncludeParagraphMark = False Then
    sReturnText = Replace(sReturnText, vbCr, "")
    End If
    End If


    l_exit:
    fGetNearestParaTextStyledIn = sReturnText
    Exit Function
    l_err:
    'black box, so that any errors return an empty string
    sReturnText = ""
    Resume l_exit
    End Function
    '----------------------------------------------------------------------------------------------------------
    'return the nearest paragraph range styled
    'defaults to Heading 1
    'NOTE: if searching forward, starts searching from the *beginning* of the passed range
    ' if searching backward, starts searching from the *end* of the passed range
    '----------------------------------------------------------------------------------------------------------
    Public Function fGetNearestParaRange(rngWhere As Range, _
    Optional sStyleName As String = "Heading 1", _
    Optional bSearchForward As Boolean = False) As Range
    Dim rngSearch As Range

    On Error GoTo l_err
    Set rngSearch = rngWhere.Duplicate
    'if searching down, then start at the beginning of our search range
    If bSearchForward Then
    rngSearch.Collapse wdCollapseStart
    'otherwise, search from the end
    Else
    rngSearch.Collapse wdCollapseEnd
    End If

    'find the range
    With rngSearch.Find
    .Wrap = wdFindStop
    .Forward = bSearchForward
    .Style = sStyleName
    'if we found it, return it
    If .Execute Then
    Set fGetNearestParaRange = rngSearch
    Else
    Set fGetNearestParaRange = Nothing
    End If
    End With

    l_exit:
    Exit Function
    l_err:
    'black box- any errors, return nothing
    Set rngSearch = Nothing
    Resume l_exit
    End Function
    [/vba]

  8. #28
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Looks good. Just a quick comment-- you don't necessarily need 2 new variables to do what you wanted to do. You could easily have used...
    sReturnText = rngReturn.ListFormat.ListString & " - " & rngReturn.Text

    However, you may want to do a little customization in order to handle both scenarios, something like?
    [VBA]
    If rngReturn.ListFormat.ListString = "" Then
    sReturnText = rngReturn.Text
    Else
    sReturnText = rngReturn.ListFormat.ListString & " - " & rngReturn.Text
    End If
    [/vba]
    That would cover both scenarios, without having to change the code for two different document types.

  9. #29
    VBAX Regular
    Joined
    Feb 2013
    Location
    Bangkok
    Posts
    9
    Location
    Hello, i am new to this forum and have been struggling on my own for a while with WORD VBA. I consider myself a newbie with regard to Word VBA, however i do have limited experience in Excel.

    I am trying to create a macro that does something very similar to what RT-PAD was working on with an additional field or column for track changes. I have asked my colleagues that when they review word documents they should make the change (addition or deletion) and the first line of the track change, they should highlight and make a comment, include an explanation of why they are proposing the change.

    My progress so far is to be able to create a table with the comments above and the track changes below, it searches for comments then once n count is reached it starts on the track changes. Not very helpful when you are reviewing each change line by line. I then tried exporting this to excel where i could sort on the page number then line number and then re-import to word (i was desperate) however i discovered the various limitations of excel with regard to character limits.

    I understand the revision collections and comment collections are treated separately and having a nested loop with the comment extraction inside the revision extraction may not work.

    Just to be clear I want my table to sequentially list the track changes and comments through a document (sorted on page number and line number). For lines of the document with track changes AND comments I want them both to be printed in a single row. Where comments or track changes appear only then blank cells can be left.

    Can someone give me an idea of the direction I need to be going to make this work? I will give it a go and then probably have to post the code for some more help.

    Thanks in advance

    Will

  10. #30
    VBAX Regular
    Joined
    Feb 2013
    Location
    Bangkok
    Posts
    9
    Location
    So i have been doing a bit of surfing and found this advice from Jay Freedman.

    So i understand for each comment or revision i will have to keep track of the position within the document using range.start and range.end.

    This is where my understandind stops. The syntax required for this is a little beyond me, can anyone give me further pointers?

    Incedentally, there may be some short notes for me just to boost my post count.... I hear you cannot attach code until you have 5 posts?

    As far as VBA is concerned, comments are completely separate from tracked
    changes. Just as the tracked changes are in the ActiveDocument.Revisions
    collection, the comments are in the ActiveDocument.Comments collection, and
    they have nothing to do with each other.

    You would need a separate part of your macro devoted to handling comments,
    with a separate loop

    Dim oCmt As Comment

    For Each oCmt In ActiveDocument.Comments
    ' extract the properties of oCmt here, like this...
    .Cells(2).Range.Text = oCmt.Author
    .Cells(3).Range.Text = oCmt.Range.Text
    Next

    This loop cannot be intermixed with the loop that handles the Revisions
    collection -- they must be separate loops. If you want the extracted table
    to put the comments in between the tracked changes in the same order they
    occur in the original document, you'll have to do that separately by keeping
    track of the .Range.Start and .Range.End values (which are, respectively,
    the number of characters from the beginning of the document to the start and
    end of the Range) and inserting or moving table rows to match.

  11. #31
    VBAX Regular
    Joined
    Feb 2013
    Location
    Bangkok
    Posts
    9
    Location
    So i have been going around in circles a little with the loops for the comments and revision inside each other. I couldn't figure out how to do this and so in the end i did away with the loops in favour of the GOTO command....... is this realistic?

    My If statement syntax is not working and so i cannot tell if the entire code is working. As you can tell i am clutching at straws a little. here is my code, if anyone can help it would be appreciated.

    I only expect this code to print the comments and revisions on the order they appear in the oDoc. I haven't thought about the problem should the comments and revisions appear on the same line. One step at a time.

    [vba]
    Set oNewDoc = ActiveDocument
    Set oDoc = Documents.Add(Visible:=True)
    Set oRange = oDoc.Range(0, 0)
    Set oTable = oDoc.Tables.Add(Range:=Selection.Range, numrows:=cCount + rCount + 1, NumColumns:=13)

    c = 1

    label1:

    If oDoc.Comments(c).Scope.Information(wdFirstCharacterColumnNumber) < _
    oDoc.Revision(r).Range.Information(wdFirstCharacterColumnNumber) Then


    'Index Number
    oTable.Cell(c + r, 1).Range.Text = c
    'Page number
    oTable.Cell(c + r, 2).Range.Text = oDoc.Comments(c).Scope.Information(wdActiveEndPageNumber)
    'The line number
    oTable.Cell(c + r, 3).Range.Text = oDoc.Comments(c).Scope.Information(wdFirstCharacterLineNumber)
    'call function to get section heading
    oTable.Cell(c + r, 4).Range.Text = fGetNearestParaTextStyledIn(oDoc.Comments(c).Scope)

    'The text marked by the comment
    oTable.Cell(c + r, 7).Range.Text = oDoc.Comments(c).Scope
    'The comment itself
    oTable.Cell(c + r, 8).Range.Text = oDoc.Comments(c).Range.Text
    'The comment author
    oTable.Cell(c + r, 9).Range.Text = oDoc.Comments(c).Author

    c = c + 1

    GoTo label1:

    Else

    r = 1

    'Type of revision
    If oRevision(r).Type = wdRevisionInsert Then
    oTable.Cell(c + r, 5).Range.Text = "Inserted"
    Else
    oTable.Cell(c + r, 5).Range.Text = "Deleted"
    End If

    'inserts the actual track change itself
    oTable.Cell(c + r, 6).Range.Text = oRevision.Range.Text = strText

    r = r + 1

    GoTo label1:

    End If
    [/vba]

  12. #32
    VBAX Regular
    Joined
    Feb 2013
    Location
    Bangkok
    Posts
    9
    Location
    I have moved on a little from my last post and solved my problem in a round about way.

    Now moving onto a yet simpler problem.

    I am using wdFirstCharacterLineNumber and wdActiveEndPageNumber to identify the position of comments and revisions, return them, then selection.sort to sort all the line items into order. The problem is, when a comment highlights text which laps over onto the second page, the page number returned is that at the end of the range whilst the revision is that of the first character.

    Occasionally this throws out my numbering.

    I don't know the syntax but what i want to do it:

    If (comment)range.start.pagenumber = range.end.pagenumber then
    do normal code
    Else
    return the page number of the start of the range.

    alternatively i would like

    Scope.Information(wdActiveEndPageNumber) to return the START page number instead of END. Can you do this using 'adjust'?

  13. #33
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    bbqq021 -- you should really start new posts with new questions, rather than ressurect old ones. If an old post contains information, then provide a link to that post in your new post.

    In addition to being good forum etiquette (hijacking threads which have been asked and answered is generally not a great approach), you may find that you have more people trying to help.

    I'm sure there is a way to do what you want to do... you probably just need to collapse the range before you test the .Information property of it.

    However, I would suggest creating a new post to get a complete answer. I've been very inactive in the last few months because I've been swamped with work.

    You've got a good chance of getting your question answered by another currently more active poster.

    Cheers.
    _______________________________________________
    Please don't cross-post without providing links to your cross-posts. We answer questions for free. Please don't waste the time of the people helping you.
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

    - Frosty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •