Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-01-2015, 05:02 AM
loes loes is offline regular expressions in footnotes Windows 8 regular expressions in footnotes Office 2013
Novice
regular expressions in footnotes
 
Join Date: Apr 2015
Posts: 1
loes is on a distinguished road
Default regular expressions in footnotes

I have two long documents, with many footnotes, that need to be formatted. Both documents present a different problem in the footnotes, which I would like to solve using a regular expression.

1. Punctuation sign (full stop) missing at the end of a footnote.
I use the following regular expression:
find (search all footnotes that do not end with a punctuation sign), use wildcards activated: ([!.\?\!])(^13)(^2)
replace (add full stop at the end of footnotes not ending with a punctuation sign): \1.\2\3


The regular expression finds the footnotes that should be corrected without any problems, but does not do anything when pressing 'replace', nor 'replace all'.

2. Footnotes separated by a white line, i.e. additional hard return.
I use the following regular expression:
find (search all footnotes that are separated from the next one by an additional hard return), use wildcards activated: (^13)(^13)(^2)
replace (remove one of both hard returns): \2\3
The regular expression, again, finds the footnotes that should be corrected without any problems, but does not do anything when pressing 'replace', nor 'replace all'.

I have the impression the paragraph mark is blocking both regular expressions (looks like Word is thinking I am replacing the paragraph mark at the end of the footnote, which is not allowed). Can anyone confirm this idea and offer some help how to solve it?

Thanks in advance!
Reply With Quote
  #2  
Old 06-05-2015, 11:03 PM
macropod's Avatar
macropod macropod is offline regular expressions in footnotes Windows 7 64bit regular expressions in footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

For 1:
Unless your footnotes have paragraphs that shouldn't terminate in a punctuation mark, you should be able to use -
Find = ([!.\?\!])(^13)
Replace = \1.\2

For 2:
For empty footnote paragraphs, except where the footnote ends with an empty paragraph, you should be able to use -
Find = (^13){2,}
Replace = ^p

Because you can't replace the final paragraph break in a footnote or endnote, there is a limit to what can be achieved via Find/Replace. A macro, however, could be used to iterate through each footnote and do the required processing.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-04-2019, 07:44 AM
wido wido is offline regular expressions in footnotes Windows 10 regular expressions in footnotes Office 2016
Novice
 
Join Date: Sep 2019
Posts: 4
wido is on a distinguished road
Default

Hi! I'm trying to accomplish #2 (replacing ^p^p with ^p in footnotes) but I'm at a loss because matches are found and clicking the "Find next" button does take me to the next occurrence, but replacing fails with no apparent error message.
I've tried both with and without wildcards, using either ^13^13 or ^p^p in the "Find" field, but to no avail.
Also, writing it as VBA code gave no different result.
As I found out here, the only thing that works is put my cursor at the start of the paragraph I want to delete and then press the Backspace key instead of the Delete key. But since my goal is coding all this, how does that translate to VBA?
This post is supposed to solve it, but it hasn't worked for me and I don't understand why because I'm still pretty new to VBA coding.
Thank you!

Last edited by wido; 09-04-2019 at 07:47 AM. Reason: Added line before last.
Reply With Quote
  #4  
Old 09-04-2019, 07:52 AM
wido wido is offline regular expressions in footnotes Windows 10 regular expressions in footnotes Office 2016
Novice
 
Join Date: Sep 2019
Posts: 4
wido is on a distinguished road
Default

Oh, it did work! I just had to fix a couple of things that weren't pasted properly from the webpage!! Thank you, solved for me (the original poster did not follow up)!
Copying/pasting here the code that worked. All credit goes to How to fix “This is not a valid action for footnotes” MS Word Error

Code:
Sub CleanReturnsInNotes()

NoteCount = ActiveDocument.Footnotes.Count
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

With Selection.Find
    .Text = "^p^p"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = False
End With

Selection.Find.Execute

On Error GoTo TrapTheError

While Selection.Find.Found
    Selection.MoveLeft
    ' The following line may trigger an error!
    Selection.Delete
    Selection.Find.Execute
Wend

GoTo TheEnd

TrapTheError:
ErrorCount = ErrorCount + 1
Selection.MoveRight
Selection.Delete

If ErrorCount < NoteCount Then Resume Next

TheEnd:

End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expressions in footnotes Regular expressions for text with complex formatting Kreol2013 Word VBA 1 04-12-2013 07:33 PM
regular expressions in footnotes Regular Expressions: match words within quotes? tinfanide Word VBA 3 02-02-2013 10:07 PM
regular expressions for empty lines eNGiNe Word 1 01-21-2013 06:38 AM
regular expressions in footnotes Regular expressions: lower case after hyphen SusanG Word 2 06-06-2012 11:58 PM
regular expressions in footnotes Regular Expressions: [!0-9] does not work??? tinfanide Excel Programming 4 05-30-2012 04:09 AM

Other Forums: Access Forums

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


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