![]() |
|
#1
|
||||
|
||||
![]()
In your sample document, you have a formfield immediately after the first footnote reference. The code was not written with such documents in mind. As written, the code moves each character after the footnote reference individually, which is obviously not possible the formfields. For your document, the code needed to be completely re-written to process all the references in reverse order and move the actual references instead of the associated text:
Code:
Sub FootnotePunctBefore() Application.ScreenUpdating = False Dim bHid As Boolean, i As Long, Rng As Range, StrBkMkNm As String With ActiveDocument bHid = .Bookmarks.ShowHidden .Bookmarks.ShowHidden = True For i = .Footnotes.Count To 1 Step -1 With .Footnotes(i) With .Reference Set Rng = .Duplicate If .Bookmarks.Count = 0 Then StrBkMkNm = "" Else StrBkMkNm = .Bookmarks(1).Name End If End With With Rng .Collapse wdCollapseStart 'Eliminate any spaces before the footnote reference Do While .Characters.First.Previous Like "[ " & Chr(160) & "]" .Characters.First.Previous.Text = vbNullString Loop 'Find the preceding puctuation, bracket, etc. Do While .Characters.First.Previous Like "[!0-9A-Za-z" & vbCr & Chr(11) & vbTab & "]" If .Characters.First.Previous.Fields.Count = 1 Then Exit Do If .Characters.First.Previous.ContentControls.Count = 1 Then Exit Do .End = .End - 1 Loop End With 'Swap the footnote/punctuation, as applicable If .Reference.Start <> Rng.Start Then Rng.FormattedText = .Reference.FormattedText If StrBkMkNm <> "" Then .Range.Bookmarks.Add StrBkMkNm, Rng .Delete End If End With Next For i = .Range.Fields.Count To 1 Step -1 With .Range.Fields(i) If .Type = wdFieldNoteRef Then Set Rng = .Result With Rng .Collapse wdCollapseStart 'Eliminate any spaces before the footnote reference Do While .Characters.First.Previous Like "[ " & Chr(160) & "]" .Characters.First.Previous.Text = vbNullString Loop 'Find the preceding puctuation, bracket, etc. Do While .Characters.First.Previous Like "[!0-9A-Za-z" & vbCr & Chr(11) & vbTab & "]" If .Characters.First.Previous.Fields.Count = 1 Then Exit Do If .Characters.First.Previous.ContentControls.Count = 1 Then Exit Do .End = .End - 1 Loop End With 'Swap the footnote/punctuation, as applicable If .Result.Start <> Rng.Start Then Rng.FormattedText = .Result.FormattedText .Delete End If End If End With Next .Bookmarks.ShowHidden = bHid End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]()
Hi Macropod, thank you so much for taking the time to look at this issue and update the code - I've run the code on my document - the code hangs for a while but I'm guessing its because it is a 200 page document so takes time to read through but it doesn't seem
to move the footnote ref before the square bracket at the end of paragraphs so ]FN becomes FN] or .]FN becomes FN]. When I show the form field codes the square brackets are all FORMTEXT - I did try changing wdFieldNoteRef to wdFieldFormTextInput but that didn't work. I'm curious to know what this line of code means and how the code picks up punctuation just from a learning point of view? Code:
"[!0-9A-Za-z" & vbCr & Chr(11) & vbTab & "]" |
#3
|
||||
|
||||
![]()
What you're seeing there is due to the ] being part of the formfield text. One can hardly put a footnote reference inside a formfield!
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
![]()
Hi Macropod, I think we may have cross wires - nothing should happen to cross references - I was enquiring how to move the footnote references that appear at the end of paragraphs to be moved to the left of the form field not actually inside it - and where they appear at the end of the paragraph with punctuation the footnote ref to be moved before the punctuation.
Capture.PNG |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
emblaw | Word | 4 | 12-08-2020 06:23 AM |
![]() |
KDuncan | Word | 6 | 04-28-2020 12:14 AM |
![]() |
michaelbriordan | Word | 3 | 06-17-2015 10:12 AM |
![]() |
bearligirl89 | Word | 3 | 11-20-2013 03:33 PM |
![]() |
jimgard | Word | 1 | 07-23-2013 11:47 AM |