• Auto set cross references (in a table)

    Author
    Topic
    #465971

    Hi

    Is it possible to automate this process? I have several documents (will get several more on a regular basis) where I have to insert cross references in a table to the changes in the document. Of course, track changes is easier but unfortunately not available on these docs. So the idea is that we have a table with a list of references to the changes in the document and the reader would be able to click on the reference & get to the change. Doing this manually is not only time consuming but kills brain cells as well.

    Is there an easy to do this? I have put in page numbers for my use at the moment but not necessary. I would be grateful for any ideas as this is killing me to boredom.

    Code:
    Section
    4.1.1 (p10)
    4.2.1 (p11)
    4.3.1 (p12)
    4.6.1 (p13)
    4.7.1 (p14)
    4.8.1 (p15)
    4.9.1 (p16-17)
    4.10. (p18-19)
    4.11.1 (p19), 4.11.2 (p19)
    5.2.2 (p20)
    5.4.2 (p22)
    5.5.2 (p23)
    5.6.2 (p24)
    5.13.2 (p30-31)
    5.14.2 (p32-33)
    5.18 to 5.22
    5.23 (p39)
    6.2 (p41)
    8.1.2 (p45)
    9.2.2 (p48)
    9.4.2 (p50)
    9.5, 9.6
    9.7.2 (p52)
    9.8.2 (p53)
    9.9
    9.10.2 (p56)
    9.15, 9.16
    
    Viewing 3 reply threads
    Author
    Replies
    • #1205964

      The cross ref / TOC uses a style to determine where to add a reference. If the changes are all in the same style you may be stuck.

      cheers, Paul

    • #1206042

      Note that this solution doesn’t attempt to deal with the special cases in your sample where it appears that more than one revision is listed on a single line. Nor does the code attempt to merge into a single revision a replacement type revision (replace = delete + add)

      If you have numbered every paragraph then the following code would do pretty much what you asked.

      Code:
      Sub CompileRevisionsTable()
        Dim aRev As Revision, x As Integer, y As String
        'put cursor at end of document to insert the reference table
        Selection.EndKey Unit:=wdStory
        ActiveDocument.TrackRevisions = False
        
        For x = 1 To ActiveDocument.Revisions.Count
          With ActiveDocument
            .Bookmarks.Add Name:="Rev" & x, Range:=.Revisions(x).Range
            .Fields.Add Range:=Selection.Range, text:="ref Rev" & x & " r h"
            Selection.TypeText vbTab & "(p "
            .Fields.Add Range:=Selection.Range, text:="pageref Rev" & x & " r h"
            Selection.TypeText ")" & vbCr
          End With
        Next x
      End Sub

      However, if the paragraph numbers in your compiled table refer to the nearest preceding heading number above the revision then the code would need to be trickier.

      • #1206096

        Note that this solution doesn’t attempt to deal with the special cases in your sample where it appears that more than one revision is listed on a single line. Nor does the code attempt to merge into a single revision a replacement type revision (replace = delete + add)

        If you have numbered every paragraph then the following code would do pretty much what you asked.

        Code:
        Sub CompileRevisionsTable()
          Dim aRev As Revision, x As Integer, y As String
          'put cursor at end of document to insert the reference table
          Selection.EndKey Unit:=wdStory
          ActiveDocument.TrackRevisions = False
          
          For x = 1 To ActiveDocument.Revisions.Count
            With ActiveDocument
              .Bookmarks.Add Name:="Rev" & x, Range:=.Revisions(x).Range
              .Fields.Add Range:=Selection.Range, text:="ref Rev" & x & " r h"
              Selection.TypeText vbTab & "(p "
              .Fields.Add Range:=Selection.Range, text:="pageref Rev" & x & " r h"
              Selection.TypeText ")" & vbCr
            End With
          Next x
        End Sub

        However, if the paragraph numbers in your compiled table refer to the nearest preceding heading number above the revision then the code would need to be trickier.

        Thanks Andrew. That is very good indeed. It does most of the things I need so I will go with it.

        Thanks again – very useful.

        • #1206124

          Thanks Andrew. That is very good indeed. It does most of the things I need so I will go with it.

          Thanks again – very useful.

          I wrote too soon. It seemed to work fine for one document but having tried on other docs, I am afraid to say it doesn’t work :-(. It comes up with 0 & Page 10 for everything.

    • #1206128

      Andrew: That’s a superb piece of code, but a Revisions collection will only be available in a document if revisions have been made when change tracking is enabled. If track changes is not available on these docs per Robie’s first post, then the Revisions count is always going to be 0.

      Robie: Can you elucidate what you mean by track changes not being available on these docs? Do you have a group policy that makes track changes unavailable? Or do you mean that you have existing documents in which revisions were made without track changes turned on, and you would now like to build an index of the revisions made in those documents?

      Either way, I don’t think you can build an index of revisions, without first making the revisions with track changes, and then using a solution like Andrew’s – because without track changes, revisions made are not going to have been marked in any way for subsequent identification.

      Gary

      • #1207198

        Andrew: That’s a superb piece of code, but a Revisions collection will only be available in a document if revisions have been made when change tracking is enabled. If track changes is not available on these docs per Robie’s first post, then the Revisions count is always going to be 0.

        Robie: Can you elucidate what you mean by track changes not being available on these docs? Do you have a group policy that makes track changes unavailable? Or do you mean that you have existing documents in which revisions were made without track changes turned on, and you would now like to build an index of the revisions made in those documents?

        Either way, I don’t think you can build an index of revisions, without first making the revisions with track changes, and then using a solution like Andrew’s – because without track changes, revisions made are not going to have been marked in any way for subsequent identification.

        Gary

        Sorry, been busy with other things lately. Gary: will come back to your question some time later.

    • #1207199

      Robie

      If the paragraph with the tracked revision is NOT numbered automatically then the cross reference to the paragraph number will always show 0. I was hoping you had numbered EVERY paragraph which had a revision (note the caveats on my first post). The page number should have been correct though so I am not sure why you are only getting page 10 unless all your tracked revisions are on this page.

      The code to cross refer to the nearest preceding numbered heading is going to be a bunch more difficult and if you haven’t used automatic numbers on headings then it may be trickier again. Your original request had some very odd variations that I wouldn’t even want to consider
      4.8.1 (p15) my code only offered this variant
      4.9.1 (p16-17) spanning pages is more complicated
      4.11.1 (p19), 4.11.2 (p19) merging numbers that fall on the same page on the same line?
      5.18 to 5.22 why don’t you want a page number here?
      9.5, 9.6 why don’t you want a page number here?

    Viewing 3 reply threads
    Reply To: Auto set cross references (in a table)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: