finding footnote-ending paragraph mark

P

Peter T. Daniels

I've just received a ms. from an author who ended every one of
hundreds of footnotes with Enter, which results in what looks on
screen like a sequence of paragraph marks -- the Enter plus the end-of-
footnote mark -- but ^p^p doesn't find them.

(I can't just delete all paragraph marks, because of multi-paragraph
footnotes.)
 
G

Graham Mayor

Try ^13 in place of ^p

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Peter T. Daniels

^13^13 found the sequence ok, but I couldn't find something to put in
the Replace box that worked.

(^13)(^13) Replace with \2 and Use Wildcards didn't do anything,
either.
 
S

Suzanne S. Barnhill

Can you not replace with ^p?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

^13^13 found the sequence ok, but I couldn't find something to put in
the Replace box that worked.

(^13)(^13) Replace with \2 and Use Wildcards didn't do anything,
either.
 
P

Peter T. Daniels

Nope; it's easy to Find the sequence -- ^13^13 and (^13)(^13)
Wildcards both work -- but Replace with any of ^13, ^p, or \2 does
nothing but send the cursor back to where it was when I clicked Find.
 
S

Suzanne S. Barnhill

I guess I meant if you're not using wildcards (you don't have to be to use
^13). But Word can be extremely bloody-minded about paragraph marks
sometimes--in footnotes, between tables, etc. While it may be possible to
write a macro to take care of this (though ISTR that even a macro wouldn't
do it for paragraph breaks between tables), in the long run you may just
have to go through and do this by hand (using Delete or Backspace, whichever
works).

If all else fails (oh, joy!), you may have to copy the text of an existing
footnote (without the paragraph marks), delete the footnote reference in the
document body, insert a new footnote, and paste the copied content into it.
Lather. Rinse. Repeat.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

Nope; it's easy to Find the sequence -- ^13^13 and (^13)(^13)
Wildcards both work -- but Replace with any of ^13, ^p, or \2 does
nothing but send the cursor back to where it was when I clicked Find.
 
P

Peter T. Daniels

Oh well, thanks.

Maybe authors should have to have graduate students type their papers
again, who know how to use these things.
 
S

Suzanne S. Barnhill

Hey, you've *seen* posts from graduate students in this NG. What makes you
think they know how to use Word any better than their professors?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

Oh well, thanks.

Maybe authors should have to have graduate students type their papers
again, who know how to use these things.
 
G

Greg Maxey

Mr. Daniels,

You might be able to clean them up with the macro posted below. Very
limited testing (two section document with a few footnotes - each
footnote ended using the enter key once). If you decide to try this,
I suggest running it on a copy of the document first.

Sub ScratchMaco()
Dim oFN As Footnote
Dim i As Long
For Each oFN In ThisDocument.Footnotes
oFN.Range.Select
With Selection
.Collapse wdCollapseStart
.Expand Unit:=wdParagraph
.MoveStartUntil Cset:=vbCr
On Error Resume Next
.Delete
On Error GoTo 0
End With
'Add to clean up a spurious space added at the end of the footnotes as
they were processed.
If oFN.Index <> ThisDocument.Footnotes.Count Then
oFN.Range.Select
oFN.Range.Characters.Last = "@"
oFN.Range.Characters.Last.Delete
End If
Next
End Sub
 
P

Peter T. Daniels

I tried it, thank you, got it as far as a QAT button, but with the
cursor either at the beginning of the file or at the beginning of the
footnotes, I clicked the button and nothing happened at all!
 
S

Suzanne S. Barnhill

That doesn't mean they are any better at it than the general run of users,
though. You'd be amazed how many people use Word all the time with no real
idea how to use it correctly (including almost everyone at Microsoft,
apparently).

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

They've been doing it since elementary school? Maybe even had classes!
 
Y

Yves Dhondt

The end of footnote paragraph marker is not an ordinary paragraph marker. It
can not be removed. That probably explains why a simple find/replace doesn't
work.

Try the following macro:

=============================
Sub RemoveEmptyParagraphsAtFootnoteEnd()
Dim note As Footnote

For Each note In ActiveDocument.Footnotes
note.Range.Select
Selection.Collapse wdCollapseEnd
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

While (Selection.Text = vbCr)
Selection.Delete
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Wend
Next
End Sub
=============================

Yves

A simple search won't work due to the way a footnote is specified. Each
footnote has to reside in its own paragraph
 
G

Greg Maxey

Mr. Daniels,

That is probably my fault as I used "ThisDocument" vice "ActiveDocument" in
the code. You most likely placed the macro in a template before pinning it
to the QAT. Changing ThisDocument to ActiveDoucment should work (it does
here) but the code was clunky to begin with. Try this instead:

Sub ScratchMaco()
Dim oFN As Footnote
Dim i As Long
For Each oFN In ActiveDocument.Footnotes
On Error Resume Next
Do While Asc(oFN.Range.Characters.Last) = 13
oFN.Range.Characters.Last.Delete
On Error GoTo 0
Loop
Next
End Sub
 
G

Greg Maxey

Yves,

<The end of footnote paragraph marker is not an ordinary paragraph marker.
It can not be removed. That probably explains why a simple
<find/replace doesn't work.

I think you are right. The behaviour of that little mark is certainly
interesting it throws a RTE 5252 if you try to delete it with VBA and it
can't even be deleted manually! That was what led to the On Error
statement in my two earlier versions. After seeing your version, I went
back to check and discovered that the mark itselt does not appear to be
physically part of the footnote range so there is no need for the error
handler or to manipulate the selection.


Sub ScratchMaco()
Dim oFN As Footnote
For Each oFN In ActiveDocument.Footnotes
Do While Asc(oFN.Range.Characters.Last) = 13
oFN.Range.Characters.Last.Delete
Loop
Next
End Sub
 
P

Peter T. Daniels

Well ... Yves posted his macro a few minutes before Mr. Maxey posted
the first of his revisions, so I tried Yves's, and it worked, and I
could watch it working -- page after page flashed by, with highlighted
footnotes. It didn't disturb the paragraph divisions within footnotes
-- yet in the code I don't see a reference to paragraph marks (as I do
see in Mr. Maxey's).

The macro did end up in the normal.dotm template; is there a way to
put a macro only into a document and not into any template at all?

Also, if I don't give it a button in the QAT, I don't know how to run
a macro. (*Word2007 Inside Out* indicates, p. 813, that doing it some
other way is clunky or inefficient anyway.)
 
Y

Yves Dhondt

The macro isn't the finest piece of code ever written. vbCr (carriage
return) is ^13 and your paragraph marker.

You can access macros from the Developer tab. If you hit the Macro button on
that tab, a list of available macros appear. You can use the "Run" button to
run any of those.

You can add the Macro button (View Macro) to your QAT. Or you can simply
press ALT+F8 (the default shortcut) to make the dialog appear.

Yves

Well ... Yves posted his macro a few minutes before Mr. Maxey posted
the first of his revisions, so I tried Yves's, and it worked, and I
could watch it working -- page after page flashed by, with highlighted
footnotes. It didn't disturb the paragraph divisions within footnotes
-- yet in the code I don't see a reference to paragraph marks (as I do
see in Mr. Maxey's).

The macro did end up in the normal.dotm template; is there a way to
put a macro only into a document and not into any template at all?

Also, if I don't give it a button in the QAT, I don't know how to run
a macro. (*Word2007 Inside Out* indicates, p. 813, that doing it some
other way is clunky or inefficient anyway.)
 
Y

Yves Dhondt

I did some checking in the open xml specification. It seems that the content
of a footnote or endnote has to be one or more block-level elements (such as
paragraphs, tables, ...) or an element containing one or more block level
elements. So it is not possible to define a footnote or endnote as a simple
run of text, there has to be a 'hard' separator at the end. I'm guessing
that is why Word is treating the marker as a special case not to be messed
with.

It also explains why it is not possible to have multiple footnotes on the
same line in Word. (I'm aware of the workaround using hidden text for the
'paragraph' marker.)

Yves
 
G

Greg Maxey

Yes he did and it works perfectly well. The reason you can watch it working
is because Yves used the selection object vice the range object. Using
selection your screen is being refreshed with each selection change The
penalty, if you want to call it that, for using the selection object over
the range object is the speed the macro will run. In many cases the speed
advantage is mute but could become significant with larger numbers of
footnotes.

Yves reference to paragraph marks is vbCr. vbCr is one of the miscellaneous
contants that the VB editor can using in place of the equivelent Chr(13).
Open your VB Editor (Alt+F11), highlight the intance of vbCr in Yves' code
and press F1. You should see the help file open with a listing of the
miscellaneous constants.
The macro did end up in the normal.dotm template; is there a way to put a
macro only into a document and not into any template at all?

Yes. With the document open, open the VB Editor. If not displayed, display
the Project Explorer (Ctrl+r). Expand the tree for the document project and
paste the code into the ThisDocument class module. When I was working of
the first edition, I was working in the VB Editor ThisDocument class module
and ran the macro by pressing the run command on the VBE toolbar (looks like
a play button on a DVD player). I do that a lot. That is why I neglected to
change ThisDocument to ActiveDocument before posting.

You can also run code using the Developer Tab>Code>Macros. Select the
appropriate document from the "Macros in" drop down. Select the macro and
press Run.
 
S

Suzanne S. Barnhill

To run a macro that's not on the QAT, click Macros on the View tab, then
View Macros. This opens the classic Macros dialog. Select your macro and
click Run. You can save a macro in a document. If you use Graham's
installation method, just select the active document instead of "All active
templates and documents" in the Macros dialog before you click Create.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

Well ... Yves posted his macro a few minutes before Mr. Maxey posted
the first of his revisions, so I tried Yves's, and it worked, and I
could watch it working -- page after page flashed by, with highlighted
footnotes. It didn't disturb the paragraph divisions within footnotes
-- yet in the code I don't see a reference to paragraph marks (as I do
see in Mr. Maxey's).

The macro did end up in the normal.dotm template; is there a way to
put a macro only into a document and not into any template at all?

Also, if I don't give it a button in the QAT, I don't know how to run
a macro. (*Word2007 Inside Out* indicates, p. 813, that doing it some
other way is clunky or inefficient anyway.)
 

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