#1
|
|||
|
|||
Help needed with moving footnotes
Hi, my first post and I am stymied by this problem!
I am in the process of writing an incredibly large book (currently 270,000 words) on the history of a glassworks. While writing this it is essential to keep track of the references and sources, hence the need for hundreds of footnotes, although some will be removed when the final edit is performed. When I started writing, I noticed that the footnotes were being included as a single word count, which I wanted to avoid. The conventional position for the footnote is immediately after the full stop in a sentence, although sometimes they are used in mid-sentence. To prevent this I decided to try positioning them immediately before the stop, but now I would like to move them all back to the conventional place. OK, so I know that ^fn (footnote special character) can be used within the Find/Replace dialogue, however, ^fn cannot be used in the 'Replace' field. So, simplistically: Find: ^fn. Replace with: .^fn is invalid. Can anyone suggest a solution? Any help is much appreciated! David |
#2
|
||||
|
||||
The following macro ensures all Footnote & Endnote references are placed after any applicable adjacent punctuation marks. Any preceding space characters are also deleted.
Code:
Sub FootnoteEndnoteFix() Application.ScreenUpdating = False Dim FtNt As Footnote, EndNt As Endnote, Rng As Range With ActiveDocument For Each FtNt In .Footnotes Set Rng = FtNt.Reference With Rng 'Eliminate any spaces before the footnote While .Characters.First.Previous.Text = " " .Characters.First.Previous.Text = vbNullString Wend 'Swap the footnote/punctuation, as applicable Select Case .Characters.Last.Next Case ".", ",", "!", "?", ":", ";" .InsertBefore .Characters.Last.Next .Characters.Last.Next.Delete End Select End With Next For Each EndNt In .Endnotes Set Rng = EndNt.Reference With Rng 'Eliminate any spaces before the endnote While .Characters.First.Previous.Text = " " .Characters.First.Previous.Text = vbNullString Wend 'Swap the endnote/punctuation, as applicable Select Case .Characters.Last.Next Case ".", ",", "!", "?", ":", ";" .InsertBefore .Characters.Last.Next .Characters.Last.Next.Delete End Select End With Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Many thanks Paul, that worked like a dream.
Just one slight problem is where a sentence finishes with a single- or double-quote mark: ... and "this is the end of the sentence123." becomes: ... and "this is the end of the sentence.123" So I think the code needs to take into account other punctuation marks to make it more universal: Quote ' Speech " I doubt that other marks would feature. Once again, I really appreciate the time you've taken Last edited by Last Chance; 06-06-2019 at 03:45 AM. |
#4
|
|||
|
|||
UPDATE:
I modified this line: Code:
Case ".", ",", "!", "?", ":", ";", """, " '" |
#5
|
||||
|
||||
That's because your code has a space before the single quote.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Yes, because it automatically inserts it. I can't seem to make it understand I don't want the space
|
#7
|
|||
|
|||
As soon as I "click away" with the mouse, the space just appears. I also pasted the code into Notebook and pasted it back, but it simply inserts the space. Confusing!
|
#8
|
|||
|
|||
I know why: it's interpreting the single quote as the beginning of a 'Comment and forcing the space.
Last edited by Last Chance; 06-06-2019 at 02:30 PM. |
#9
|
||||
|
||||
That's happening because:
Case ".", ",", "!", "?", ":", """, " '", ";" should be: Case ".", ",", "!", "?", ":", """", "'", ";"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
Paul, I know that, but if I type "'" in the Visual Basic Editor, the end result is " '" - it is the editor that's adding the space and there's no way I can prevent this. As mentioned in my previous reply, VBE is interpreting this to be a Comment and forcing the space.
If there is no other way around this then I can perform a 'Find' in Word and go through it instance by instance, but it's a bit tedious! Thanks again, your help has already saved me an incalculable amount of time. |
#11
|
||||
|
||||
You need to look more closely at what I posted. It works.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
I see - the double-quotes surrounding the double double-quotes and (I assume) the order of the definitions. Not everyone's eyes can pick that up immediately!
But while it worked for the double-quotes, I still can't get it to work for the single quote (') - I pasted your line into the script so there was no ambiguity. Any ideas? |
#13
|
|||
|
|||
This adaptation of Paul's code seems to work to move the after a " ' and .
Code:
Sub FootnoteEndnoteFix() Application.ScreenUpdating = False Dim FtNt As Footnote, EndNt As Endnote, Rng As Range With ActiveDocument For Each FtNt In .Footnotes Set Rng = FtNt.Reference While Rng.Characters.First.Previous.Text = " " Rng.Characters.First.Previous.Text = vbNullString Wend 'Swap the footnote/punctuation, as applicable Do Set Rng = FtNt.Reference Select Case Rng.Characters.Last.Next Case ".", ",", "!", "?", ":", ";", "'", """", ChrW(8221), ChrW(8217) Rng.InsertBefore Rng.Characters.Last.Next Rng.Characters.Last.Next.Delete Case Else Exit Do End Select Loop Next For Each EndNt In .Endnotes Set Rng = FtNt.Reference While Rng.Characters.First.Previous.Text = " " Rng.Characters.First.Previous.Text = vbNullString Wend 'Swap the footnote/punctuation, as applicable Do Set Rng = FtNt.Reference Select Case Rng.Characters.Last.Next Case ".", ",", "!", "?", ":", ";", "'", """", ChrW(8221), ChrW(8217) Rng.InsertBefore Rng.Characters.Last.Next Rng.Characters.Last.Next.Delete Case Else Exit Do End Select Loop Next End With Application.ScreenUpdating = True End Sub |
#14
|
|||
|
|||
Many thanks Greg, that's fixed it.
One Happy Bunny |
#15
|
||||
|
||||
Greg's:
Case ".", ",", "!", "?", ":", ";", "'", """", ChrW(8221), ChrW(8217) is functionally the same as: Case ".", ",", "!", "?", ":", ";", "'", """", "’", "”"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to change superscript footnotes into genuine Word footnotes | Knounte29 | Word VBA | 41 | 01-16-2020 04:48 PM |
creating manuscript w/footnotes from separate documents containing chapters with footnotes-word 2010 | Dottie | Publisher | 0 | 02-19-2017 03:18 PM |
Convert manual cross references in footnotes to other footnotes to automatic cross references | ghumdinger | Word VBA | 7 | 11-20-2014 11:47 PM |
Moving cell content without moving borders & shading? | unittwentyfive | Excel | 1 | 10-25-2013 12:56 PM |
Moving formula range multiple cells when moving sum over one cell | FraserKitchell | Excel | 4 | 02-26-2010 10:38 AM |