Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-01-2012, 07:32 AM
Boatwrenchv8's Avatar
Boatwrenchv8 Boatwrenchv8 is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Novice
Pasting endnotes and X-Refs into another document
 
Join Date: Apr 2012
Posts: 23
Boatwrenchv8 is on a distinguished road
Default Pasting endnotes and X-Refs into another document

I have a long file that contains about 6 tables containing data with endnotes and cross references to endnotes (the source). This file is to have each table copied and pasted into different places in a larger document (the target), which also contains endnotes and cross references. The two files on their own are fine and are correct formatted using Word’s cross references and endnotes. When I do a Ctrl-A and F9 to the target document, the endnotes do update their numbers in the original and pasted in sections and the cross references do work, but, the cross references are higher up in the document (towards page 1), than the endnote the cross reference is referring to.



Is there any way to fix this so the first cross reference to an endnote is an endnote, and all further references below the first instance are cross references?
Reply With Quote
  #2  
Old 06-05-2012, 12:05 PM
macropod's Avatar
macropod macropod is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,341
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

So what you want to do is to find NOTEREF fields whose location precedes the note to which they refer, then swap them around. Correct? Should be quite doable - it's just a matter of comparing the ranges for the two items, then using cut & paste for the re-locations.

I'm working on a uni assignment this week, so it'd probably be a day or two before I could take more of a look at it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-07-2012, 08:52 PM
macropod's Avatar
macropod macropod is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,341
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Boatwrench,

Try:
Code:
Sub Test()
Application.ScreenUpdating = False
Dim Fld As Field, FtNtRng As Range, FldRng As Range, i As Long
With ActiveDocument
  For Each Fld In .Fields
    If Fld.Type = wdFieldNoteRef Then
      Set FldRng = Fld.Code
      i = Fld.Result
      While FldRng.Fields.Count = 0
        FldRng.End = FldRng.End + 1
      Wend
      Set FtNtRng = .Footnotes(i).Reference
      If FtNtRng.End > FldRng.End Then
        FldRng.Fields(1).Delete
        FtNtRng.Cut
        FldRng.Paste
        FtNtRng.InsertCrossReference ReferenceType:="Footnote", ReferenceKind:= _
          wdFootnoteNumberFormatted, ReferenceItem:=i, InsertAsHyperlink:=True
        If FldRng.Characters.First = " " Then FldRng.Characters.First = vbNullString
        .Fields.Update
      End If
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub
PS: The above code is for footnotes. For endnotes, use:
Code:
Sub Test()
Application.ScreenUpdating = False
Dim Fld As Field, EndNtRng As Range, FldRng As Range, i As Long
With ActiveDocument
  For Each Fld In .Fields
    If Fld.Type = wdFieldNoteRef Then
      Set FldRng = Fld.Code
      i = Fld.Result
      While FldRng.Fields.Count = 0
        FldRng.End = FldRng.End + 1
      Wend
      Set EndNtRng = .Endnotes(i).Reference
      If EndNtRng.End > FldRng.End Then
        FldRng.Fields(1).Delete
        EndNtRng.Cut
        FldRng.Paste
        EndNtRng.InsertCrossReference ReferenceType:="Endnote", ReferenceKind:= _
          wdEndnoteNumberFormatted, ReferenceItem:=i, InsertAsHyperlink:=True
        If FldRng.Characters.First = " " Then FldRng.Characters.First = vbNullString
        .Fields.Update
      End If
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub
With endnotes, you may have the added complication of section-based vs document-based end noting. The above code assumes the latter.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 06-09-2012, 11:32 AM
Boatwrenchv8's Avatar
Boatwrenchv8 Boatwrenchv8 is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Novice
Pasting endnotes and X-Refs into another document
 
Join Date: Apr 2012
Posts: 23
Boatwrenchv8 is on a distinguished road
Default

Thank you very much Macropod. you are correct, it is document based endnoting. As soon as I get this document in my hands again, I will try this code out and get back to you.
Reply With Quote
  #5  
Old 08-07-2012, 06:35 PM
Boatwrenchv8's Avatar
Boatwrenchv8 Boatwrenchv8 is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Novice
Pasting endnotes and X-Refs into another document
 
Join Date: Apr 2012
Posts: 23
Boatwrenchv8 is on a distinguished road
Default

Hello again. I finally got the document back again and ran your endnote version of the code. The code did not work properly and gave an error. I am currently putting together a sample file and will post ASAP.
Reply With Quote
  #6  
Old 08-07-2012, 07:31 PM
Boatwrenchv8's Avatar
Boatwrenchv8 Boatwrenchv8 is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Novice
Pasting endnotes and X-Refs into another document
 
Join Date: Apr 2012
Posts: 23
Boatwrenchv8 is on a distinguished road
Default

Attached are the original and the fixed versions of the sample file. The original has the endnotes and cross references mixed and not in order, the final has the endnotes first and the cross references that correspond to the correct endnote later. The endnotes and cross references are also in numerical order in the fixed version. This sample is built off of the actual document. The actual document is 105 pages long, contains over 100 endnotes and over 200 cross references. Thank you for your help with this.
Attached Files
File Type: docx Endnote and Xref problem ORIGINAL.docx (22.2 KB, 9 views)
File Type: docx Endnote and Xref problem FIXED.docx (22.4 KB, 8 views)
Reply With Quote
  #7  
Old 08-07-2012, 10:17 PM
macropod's Avatar
macropod macropod is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,341
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I think the code got tripped up with the multiple cross-references to the same endnotes. Try:
Code:
Sub Test()
Application.ScreenUpdating = False
Dim Fld As Field, EndNtRng As Range, FldRng As Range, i As Long, j As Long, Rng As Range, RngFld As Field
With ActiveDocument
  For Each Fld In .Fields
    If Fld.Type = wdFieldNoteRef Then
      Set FldRng = Fld.Code
      i = Fld.Result
      While FldRng.Fields.Count = 0
        FldRng.End = FldRng.End + 1
      Wend
      Set EndNtRng = .Endnotes(i).Reference
      If EndNtRng.End > FldRng.End Then
        FldRng.Fields(1).Delete
        EndNtRng.Cut
        FldRng.Paste
        FldRng.Style = "EndNote Reference"
        j = FldRng.Endnotes(1).Index
        EndNtRng.InsertCrossReference ReferenceType:="Endnote", ReferenceKind:= _
          wdEndnoteNumberFormatted, ReferenceItem:=j, InsertAsHyperlink:=True
        If FldRng.Characters.First = " " Then FldRng.Characters.First = vbNullString
        Set Rng = FldRng
        Rng.End = ActiveDocument.Range.End
        If i <> j Then
          For Each RngFld In Rng.Fields
            If RngFld.Type = wdFieldNoteRef Then
              If RngFld.Result = i Then
                Set FldRng = RngFld.Code
                While FldRng.Fields.Count = 0
                  FldRng.End = FldRng.End + 1
                Wend
                FldRng.Fields(1).Delete
                FldRng.InsertCrossReference ReferenceType:="Endnote", ReferenceKind:= _
                  wdEndnoteNumberFormatted, ReferenceItem:=j, InsertAsHyperlink:=True
              End If
            End If
          Next
        End If
      End If
      .Fields.Update
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub
Note that this may leave some of your reference sequences out of order, but at least it gets the endnote:cross-reference arrangement right.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 08-15-2012, 11:14 AM
Boatwrenchv8's Avatar
Boatwrenchv8 Boatwrenchv8 is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Novice
Pasting endnotes and X-Refs into another document
 
Join Date: Apr 2012
Posts: 23
Boatwrenchv8 is on a distinguished road
Default

Thank you for your code Macropod. In my sample document, it worked perfectly except for the ordering like you had said. However, in the actual document it didn't work and would throw a run-time error 13, type mismatch at the line ' i = Fld.Result ', hovering over it reveals the field is "Error! Bookmark not defined". I created another sample document that causes the same error as the actual document. I have experimented with this and cannot cause the links not to break as they are. I thought it should be a matter of doing a select all and update all fields but I have not found where in the code to put that so it works.

Thank you for your help and continued help on this. The actual document I was working on is out of my hands again (I had to do the fixes to it manually), but am certain it will or another like it will come to me soon.
Attached Files
File Type: docx Longer Document Endnote and Xref problem ORIGINAL.docx (23.3 KB, 10 views)
Reply With Quote
  #9  
Old 08-15-2012, 04:50 PM
macropod's Avatar
macropod macropod is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,341
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, try it this way. The new code should also be more efficient than the old, plus (unlike the old) it'll process cross-references in footnotes, endnotes, textboxes, etc.
Code:
Sub Test()
Application.ScreenUpdating = False
Dim Fld As Field, EndNtRng As Range, FldRng As Range, i As Long, j As Long
Dim Rng As Range, StrOld As String, StrNew As String
With ActiveDocument
  For Each Fld In .Fields
    If Fld.Type = wdFieldNoteRef Then
      Set FldRng = Fld.Code
      i = Fld.Result
      While FldRng.Fields.Count = 0
        FldRng.End = FldRng.End + 1
      Wend
      Set EndNtRng = .Endnotes(i).Reference
      If EndNtRng.End > FldRng.End Then
        StrOld = FldRng.Fields(1).Code.Text
        FldRng.Fields(1).Delete
        EndNtRng.Cut
        FldRng.Paste
        FldRng.Style = "EndNote Reference"
        j = FldRng.Endnotes(1).Index
        EndNtRng.InsertCrossReference ReferenceType:="Endnote", ReferenceKind:= _
          wdEndnoteNumberFormatted, ReferenceItem:=j, InsertAsHyperlink:=True
        If FldRng.Characters.First = " " Then FldRng.Characters.First = vbNullString
        StrNew = EndNtRng.Words.First.Fields(1).Code.Text
        ActiveWindow.View.ShowFieldCodes = True
        For Each Rng In .StoryRanges
          With Rng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = StrOld
            .Replacement.Text = StrNew
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
            .Execute Replace:=wdReplaceAll
          End With
          Rng.Fields.Update
        Next
        ActiveWindow.View.ShowFieldCodes = False
      End If
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pasting endnotes and X-Refs into another document Separating endnotes from text kenglade Word 22 09-14-2012 04:10 PM
Pasting endnotes and X-Refs into another document Copying endnotes kenglade Word 4 12-03-2011 01:26 PM
Index entries in endnotes perhj Word 0 06-19-2011 09:28 AM
Pasting endnotes and X-Refs into another document Mass Update of Cross-Refs MS2010 judicial85 Word 1 03-08-2011 10:33 PM
Problems with pasting into another document OneDayJD Word 0 04-25-2010 07:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:09 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft