How to search/replace punctuation and footnote refs

D

DWM

Hello! I'm working on a 300 page manuscript with quotation marks and other
punctuation placed after footnote refs in the body text. For this publisher,
the punctuation should be before the footnotes, not after.

For example, I would like to use wildcards to search for (^f)" and replace
with "\1 but this won't work.
Can anyone help? Wildcards don't work with footnote refs, and searching for
superscripts won't allow me to automate it over the whole doc.
Many thanks,
David
 
G

Graham Mayor

As you havew gathered you cannot use ^f in a wildcard search, so with a bit
of lateral thinking, there may be a simpler method, though it does not
immediately come to mind, but the following should do the trick.

I have included all the likely punctuation in the vPunct = Array(). You can
add or remove any from that array as required (Check Insert > symbol for the
character numbers)

Sub SwapFootnotesAndPunctuation()
Dim sText As String
Dim vPunct As Variant
Dim i As Long
vPunct = Array(Chr(33), Chr(34), Chr(44), Chr(46), _
Chr(58), Chr(59), Chr(63), Chr(146), Chr(148))
For i = LBound(vPunct) To UBound(vPunct)
With Selection
With .Find
.ClearFormatting
.Text = "^f"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
.MoveRight Unit:=wdCharacter, Count:=1
.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
sText = Selection
If sText = vPunct(i) Then
With Selection
.Cut
.MoveLeft Unit:=wdCharacter, Count:=1
.Paste
End With
End If
Next i
End Sub

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Herb Tyson [MVP]

^2 can be used instead of ^f to find footnote and endnote reference marks in
a wildcard search. Hence:

Find what:(^0148)(^2)

Replace with:\2\1

does what you want if you're using smart quotes, or just (") if you're using
straight quotes. To cover a variety of different kinds of punctuations, you
could construct your own wildcard using ([",^0148,',^0146]), which would
cover both smart and straight versions of " and '.
 
D

DWM

Dear Graham,

Thank you very much for the script. Works great!

Have a great weekend!
David
 
D

DWM

Dear Herb,

Many thanks for that solution.
It works very well, and I will indeed use char nums more often.

Enjoy the weekend,
David

Herb Tyson said:
^2 can be used instead of ^f to find footnote and endnote reference marks in
a wildcard search. Hence:

Find what:(^0148)(^2)

Replace with:\2\1

does what you want if you're using smart quotes, or just (") if you're using
straight quotes. To cover a variety of different kinds of punctuations, you
could construct your own wildcard using ([",^0148,',^0146]), which would
cover both smart and straight versions of " and '.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog: http://word2007bible.herbtyson.com
Web: http://www.herbtyson.com
DWM said:
Hello! I'm working on a 300 page manuscript with quotation marks and other
punctuation placed after footnote refs in the body text. For this
publisher,
the punctuation should be before the footnotes, not after.

For example, I would like to use wildcards to search for (^f)" and replace
with "\1 but this won't work.
Can anyone help? Wildcards don't work with footnote refs, and searching
for
superscripts won't allow me to automate it over the whole doc.
Many thanks,
David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top