![]() |
|
#16
|
|||
|
|||
|
Hi Macropod thank you for your suggestion - I replaced with .Delete but that gave an error 5904 cannot edit range.
|
|
#17
|
||||
|
||||
|
Try:
Code:
Sub EndNoteFootNotePunctCheck()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
'Process EndNotes
For i = .Endnotes.Count To 1 Step -1
Call SetPunctAfter(.Endnotes(i).Reference)
Next
'Process FootNotes
For i = .Footnotes.Count To 1 Step -1
Call SetPunctAfter(.Footnotes(i).Reference)
Next
'Process EndNote/FootNote References
For i = .Range.Fields.Count To 1 Step -1
With .Range.Fields(i)
If .Type = wdFieldNoteRef Then
Call SetPunctAfter(.Result)
End If
End With
Next
End With
Application.ScreenUpdating = True
End Sub
Sub SetPunctAfter(Rng As Range)
With Rng.Duplicate
.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
If .Characters.First.Previous.Fields(1).Result = "]" Then
.Start = .Characters.First.Previous.Fields(1).Result.Start + 1
Else
Exit Do
End If
End If
If .Characters.First.Previous.ContentControls.Count = 1 Then
If .Characters.First.Previous.ContentControls(1).Range.Text = "]" Then
.Start = .Characters.First.Previous.ContentControls(1).Range.Start + 1
Else
Exit Do
End If
End If
.Start = .Start - 1
Loop
'Swap the footnote/punctuation, as applicable
If .Start <> Rng.Start Then
Rng.Collapse wdCollapseEnd
.Cut
Rng.Paste
End If
End With
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#18
|
|||
|
|||
|
Hi Macropod, thank you so much for the new code, I've run it on a 153 page contract today and all looking good - is there a way to tell the code to ignore "quotes", apostrophe's and (parenthesis) as its moving the Footnote Reference in the wrong place, it only needs to move for periods, semi-colons, colons and question marks
|
|
#19
|
||||
|
||||
|
Simply edit:
Do While .Characters.First.Previous Like "[!0-9A-Za-z" & vbCr & Chr(11) & vbTab & "]" For example: Do While .Characters.First.Previous Like "[!0-9A-Za-z,’”)" & vbCr & Chr(11) & vbTab & "]"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#20
|
|||
|
|||
|
Hi Macropod, thanks for the update, I got a Syntax error so I changed the code to:
Code:
Do While .Characters.First.Previous Like "[!0-9A-Za-z" & Chr(39) & Chr(34) & Chr(41) & vbCr & Chr(11) & vbTab & "]" Thank you so much for your help, really appreciate it. Before I close this thread as solved - I've got some rogue spaces between the footnote reference and punctuation after running the code - I've tried adding the following at the end of the Sub SetPunctAfter macro but it doesn't seem to be working - it works when I do a normal find and replace but not when in the code. Code:
With Rng.Find .text = "(^2)[ ]([.,:;\?\!])" .Replacement.text = "\1\2" .Execute Replace:=wdReplaceAll End With |
|
#21
|
||||
|
||||
|
Simply insert:
Code:
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
End with
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#22
|
|||
|
|||
|
Hi Macropod, unfortunately that didn't work as its looking for a space before the footnote reference - when I run the whole code I am getting instances where there is a space in between a footnote reference and punctuation, mainly at the end of paragraphs - I've checked that this wasn't present before running the whole code, not sure what to change the last bit of code to.
Capture.PNG |
|
#23
|
||||
|
||||
|
OK, between the final 'Next' and 'End With', insert:
Code:
With .Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([ ^s]{1,})([,.;:\?\!^13^l^t])"
.Replacement.Text = "\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#24
|
|||
|
|||
|
Thanks so much Macropod that seems to have fixed the issue
|
|
#25
|
|||
|
|||
|
I have copied and used with success this code by macropod:
Application.ScreenUpdating = False Dim FtNt As Footnote Dim Rng As Range 'Dim Fld As Field With ActiveDocument For Each FtNt In .Footnotes Set Rng = FtNt.Reference With Rng 'Delete spaces etc. Do While .Characters.First.Previous Like "[ " & Chr(160) & "]" .Characters.First.Previous.Text = vbNullString Loop 'Invert ref. number and punctuation 'MsgBox .Characters.First.Previous Do While Not .Characters.First.Previous Like "[0-9A-Za-z]" And Not .Characters.First.Previous Like "‹" And Not .Characters.First.Previous Like "«" .InsertAfter .Characters.First.Previous .Characters.First.Previous.Delete Loop End With Next End With Thanks a lot for this! My problem is that I want the inversion to occur only in paragraphs with no left indent. How to I modify the code so that left-indented paragraphs are skipped? Thank you for your time! |
|
#26
|
||||
|
||||
|
RobiNew
You've piggybacked on someone else's thread and it isn't clear what it is that you are trying to achieve. Maybe explain what the code is supposed to find and what it needs to do when it finds that. And post a sample document that shows the 'before' state that you want the code to work on.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#27
|
|||
|
|||
|
I apologize! I'm new to these procedures. My aim is to invert reference numbers and punctuation. This I obtained with Macropod's code here below (slightly adapted with regard to some special quotation marks). However, in the text some of the paragraphs involved are left-indented and in these I don't want the inversion to operate. How do I modify (or add to) the code so that the sequence 'punctuation-ref.number' is left untouched in left-indented paragraphs? Thank you for your time!
This is the code I adapted: Quote:
|
|
#28
|
||||
|
||||
|
Maybe try this modification
Code:
Sub ReconfigFootnotes()
Dim FtNt As Footnote, Rng As Range
With ActiveDocument
For Each FtNt In .Footnotes
Set Rng = FtNt.Reference
With Rng
If Rng.Paragraphs(1).LeftIndent = 0 Then
'Delete spaces etc.
Do While .Characters.First.Previous Like "[ " & Chr(160) & "]"
.Characters.First.Previous.Text = vbNullString
Loop
'Invert ref. number and punctuation
Do While Not .Characters.First.Previous Like "[0-9A-Za-z]" And Not .Characters.First.Previous Like "‹" And Not .Characters.First.Previous Like "«"
.InsertAfter .Characters.First.Previous
.Characters.First.Previous.Delete
Loop
End If
End With
Next
End With
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#29
|
|||
|
|||
|
Many thanks, Guessed! That is simple and perfect.
Now I'm trying to devise a macro to convert all strings in italics to an italics style. But all I can get is a very long and clumsy code sequence. Is there a simple way to do it? |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Footnote references in the footnote section losing their style when cut+pasted from same doc
|
emblaw | Word | 4 | 12-08-2020 06:23 AM |
Fix footnote and endnote references to arabic numbers everywhere?
|
KDuncan | Word | 6 | 04-28-2020 12:14 AM |
Word Find won't move out of footnote
|
michaelbriordan | Word | 3 | 06-17-2015 10:12 AM |
How do I keep footnote references and text on the same page
|
bearligirl89 | Word | 3 | 11-20-2013 03:33 PM |
Multiple footnote references
|
jimgard | Word | 1 | 07-23-2013 11:47 AM |