VBA Macro for Footnotes

B

bruno

Hi,

Re. "VBA Macro for Footnotes" - convert footnote numbers to pure text and
add the footnotes as a list at the end of the document, without any other
references than the numbers - in Word 2003 SP3.

Similar matter was dealt with in recent conversation "VBA Macro For
FootNotes" (5/25/2009) - where the list of footnotes was to be placed in a
new document -, and i also found an older conversation "Convert footnotes to
ordinary text" (sept. 2007) where the footnote text was to be put directly in
the body text.

By combining the solutions found there I think it should be no problem to
get the solution to my requirement, but it is not as simple as that, at least
not for someone like me: my skills go scarcely beyond using the macro
recorder.

Below i add my macro which I combined of the codes suggested in above
mentioned conversations. It stops at the first appearence of
rngfoot.Range.InsertParagraphAfter

Could someone please tell me what is wrong ?

sub
Dim docfoot As Footnotes
Dim i As Long
Dim rngfoot As Range
Dim fn As Word.Footnote
Dim rngFN As Word.Range

If ActiveDocument.Footnotes.Count > 0 Then
Set docfoot = ActiveDocument.Footnotes
Else
MsgBox "There are no footnotes in this document.", _
vbExclamation, "Exit"
Exit Sub
End If

Set rngfoot = ActiveDocument.Sections.Last
rngfoot.Range.InsertParagraphAfter
rngfoot.Range.InsertParagraphAfter

With docfoot
For i = 1 To .Count
rngfoot.Range.InsertAfter .Item(i).Range.Text
rngfoot.Range.InsertParagraphAfter

Set fn = ActiveDocument.Footnotes(i)

Set rngFN = fn.Reference
rngFN.Collapse wdCollapseEnd

rngFN.Range.InsertAfter "[ & i & ]"
fn.Delete

Next
End With
End Sub

It cost me a lot of time to come so far, was it all in vain?
bruno
 
P

Peter T. Daniels

Are you submitting a book ms. to a publisher that requires a separate
file of endnotes?

Hi bruno,

It would help if you said what it is you're trying to do ...

--
Cheers
macropod
[Microsoft MVP - Word]



bruno said:
Re.  "VBA Macro for Footnotes" - convert footnote numbers to pure text and
add the footnotes as a list at the end of the document, without any other
references than the numbers - in Word 2003 SP3.  
Similar matter was dealt with in recent conversation "VBA Macro For
FootNotes" (5/25/2009) - where the list of footnotes was to be placed in a
new document -, and i also found an older conversation "Convert footnotes to
ordinary text" (sept. 2007) where the footnote text was to be put directly in
the body text.
By combining the solutions found there I think it should be no problem to
get the solution to my requirement, but it is not as simple as that, atleast
not for someone like me: my skills go scarcely beyond using the macro
recorder.
Below i add my macro which I combined of the codes suggested in above
mentioned conversations. It stops at the first appearence of
       rngfoot.Range.InsertParagraphAfter
Could someone please tell me what is wrong ?
sub
   Dim docfoot As Footnotes
   Dim i As Long
   Dim rngfoot As Range
   Dim fn As Word.Footnote
   Dim rngFN As Word.Range
   If ActiveDocument.Footnotes.Count > 0 Then
       Set docfoot = ActiveDocument.Footnotes
   Else
       MsgBox "There are no footnotes in this document.", _
       vbExclamation, "Exit"
       Exit Sub
   End If
   Set rngfoot = ActiveDocument.Sections.Last
       rngfoot.Range.InsertParagraphAfter
       rngfoot.Range.InsertParagraphAfter
   With docfoot
   For i = 1 To .Count
       rngfoot.Range.InsertAfter .Item(i).Range.Text
       rngfoot.Range.InsertParagraphAfter
       Set fn = ActiveDocument.Footnotes(i)
       Set rngFN = fn.Reference
       rngFN.Collapse wdCollapseEnd
       rngFN.Range.InsertAfter "[ & i & ]"
       fn.Delete
   Next
   End With
End Sub
It cost me a lot of time to come so far, was it all in vain?
bruno-
 
B

bruno

What i am trying to do ? ... Quite often I need to combine two long Word
documents (with many footnotes) side by side in two columns of an Excel table
(to allow paragraph alignment) - keeping essential text formatting like bold
and italic, the para numbers, the footnote numbers in the text and the
footnotes listed at the end of the table, they can have same font size and
colour as body text.

To do this I convert the text to table in Word and then copy and paste the
table to Excel. When I have my table completed in Excel i copy it back to a
new Word document for further processing (formatting, save, print).

The footnotes cause two problems:
1. In Excel the cells containing footnote numbers appear as links in small
fontsize and colour. To change this i deactivate hyperlinks and adapt the
font size.
2. And when I copy and paste the table back to Word the footnotes appear
again in another colour and underlined, and again I have to correct this.

I think these problems should be avoided by executing the following task in
the original Word documents:
-- break the links between footnote numbers in the text and the footnotes
and make appear both as ordinary text, with footnotes listed at the end of
the document (thus not as "endnotes"). The links are not required for my
purposes.

It is this task i am trying to automise with my macro. Can you tell me how
to make it work ?

bruno
 
P

Peter T. Daniels

But why do you go through Excel, instead of simply creating a Word
table?

Or, if notes 1-25 have to be in col. 1 and notes 26-50 in col. 2,
tables in a two-column section?
 
B

bruno

My need is to combine two long Word documents (with many footnotes) side by
side in two columns of one table. Excel, because it facilitates paragraph
alignment.
 
P

Peter T. Daniels

What are you doing more easily in Excel than in Word, that justifies
all the complications involved in switching documents between the two
programs (including turning footnotes into static text)?
 
M

macropod

Hi Bruno,

I can't see how Excel helps paragraph alignment any better than a Word table (which you can split at paragraph breaks).

In any event, if you're looking for the differences between the two documents, there are better ways (eg Tools|Merge Documents or a
macro that simply goes though each para looking for & highlighting the differences).
 
B

bruno

So you, macropod and Peter, suggest to do all of it "simply" in Word.

But isn't my question just concerning a VBA macro in Word ?
If it is so simple why don't you have a look at it and tell me what is wrong
with it?

Well, anyhow, thank you for bothering.
--
bruno


macropod said:
Hi Bruno,

I can't see how Excel helps paragraph alignment any better than a Word table (which you can split at paragraph breaks).

In any event, if you're looking for the differences between the two documents, there are better ways (eg Tools|Merge Documents or a
macro that simply goes though each para looking for & highlighting the differences).
 
P

Peter T. Daniels

Me, I've never used VBA for anything. Why do you want to make it so
complicated??

What can an Excel table do with text that a Word table can't?
 
P

Pesach Shelnitz

Hi Bruno,

The following macro inserts a superscripted number at the location of each
footnote, copies the text to a list at end of the document, and deletes the
foonotes. Note that in this simple version the footnotes will be numbered 1,
2, 3, etc. regardless of the original numbering and that the footnote text
will be copied without formatting.

Sub ConvertFootnotesToList()

Dim num As Long
Dim myString As String

If ActiveDocument.Footnotes.Count = 0 Then
MsgBox "There are no footnotes in this document."
Exit Sub
End If
With Selection
.HomeKey wdStory
For num = 1 To ActiveDocument.Footnotes.Count
.GoToNext wdGoToFootnote
.Font.Superscript = True
.TypeText Text:=CStr(num)
.Font.Superscript = False
.Expand wdWord
With ActiveDocument.Footnotes(1)
myString = myString & CStr(num) & _
". " & .Range.Text & vbCrLf
.Delete
End With
Next
.EndKey wdStory
.InsertAfter myString
.Collapse Direction:=wdCollapseEnd
End With
End Sub

If this macro does what you want, I suggest that you start a new thread and
explain what you want to do next. I agree with the others that you should be
able to do what you want in Word without moving over to Excel and back.
 
P

Peter T. Daniels

This could be useful for authors who are stuck with a backward
publisher that insists on having the notes in a separate file (because
they will be published as book endnotes).

As a copyeditor I've worked on several books for a publisher that does
it that way -- so I have to have two files open at all times, taking
up screen space -- and, moreover, who insists that editing not be done
with Track Changes, but by in fact imitating Track Changes with
deletions and insertions marked, and queries typed into the text
inside brackets.

Hi Bruno,

The following macro inserts a superscripted number at the location of each
footnote, copies the text to a list at end of the document, and deletes the
foonotes. Note that in this simple version the footnotes will be numbered1,
2, 3, etc. regardless of the original numbering and that the footnote text
will be copied without formatting.

Sub ConvertFootnotesToList()

    Dim num As Long
    Dim myString As String

    If ActiveDocument.Footnotes.Count = 0 Then
       MsgBox "There are no footnotes in this document."
       Exit Sub
    End If
    With Selection
        .HomeKey wdStory
        For num = 1 To ActiveDocument.Footnotes.Count
            .GoToNext wdGoToFootnote
            .Font.Superscript = True
            .TypeText Text:=CStr(num)
            .Font.Superscript = False
            .Expand wdWord
            With ActiveDocument.Footnotes(1)
                myString = myString & CStr(num) & _
                    ". " & .Range.Text & vbCrLf
                .Delete
            End With
        Next
        .EndKey wdStory
        .InsertAfter myString
        .Collapse Direction:=wdCollapseEnd
    End With
End Sub

If this macro does what you want, I suggest that you start a new thread and
explain what you want to do next. I agree with the others that you shouldbe
able to do what you want in Word without moving over to Excel and back.

--
Hope this helps,
Pesach Shelnitz



Peter T. Daniels said:
Me, I've never used VBA for anything. Why do you want to make it so
complicated??
What can an Excel table do with text that a Word table can't?
So you, macropod and Peter, suggest to do all of it "simply" in Word.
But isn't my question just concerning a VBA macro in Word ?
If it is so simple why don't you have a look at it and tell me what is wrong
with it?
Well, anyhow, thank you for bothering.
--
bruno
:
Hi Bruno,
I can't see how Excel helps paragraph alignment any better than a Word table (which you can split at paragraph breaks).
In any event, if you're looking for the differences between the twodocuments, there are better ways (eg Tools|Merge Documents or a
macro that simply goes though each para looking for & highlighting the differences).
--
Cheers
macropod
[Microsoft MVP - Word]
My need is to combine two long Word documents (with many footnotes) side by
side in two columns of one table. Excel, because it facilitates paragraph
alignment.
 
M

macropod

Hi bruno,

Why? Because you don't need the macro if you're doing it in Word.

To do the comparison in Word:
1. Select the 1st document and convert its contents to a table, using the paragraphs as the text separators.
2. Reduce the column width to half the page width
3. Repeat steps 1 & 2 for the 2nd document
4. Copy the table from one of the documents
5. In the other document, place the insertion point at the end-of-row marker for the 1st row in the table, then paste the other
table there.

You now have a two-column table containing the contents of both documents. The footnotes from both will also be interspersed, for
ease of comparison.

If you find yourself in a situation where the paragraphs get out of synch because of differences between the documents, it's a
simple matter to insert one or more cells into whichever column requires it to restore the synchronisation.

--
Cheers
macropod
[Microsoft MVP - Word]


bruno said:
So you, macropod and Peter, suggest to do all of it "simply" in Word.

But isn't my question just concerning a VBA macro in Word ?
If it is so simple why don't you have a look at it and tell me what is wrong
with it?

Well, anyhow, thank you for bothering.
--
bruno


macropod said:
Hi Bruno,

I can't see how Excel helps paragraph alignment any better than a Word table (which you can split at paragraph breaks).

In any event, if you're looking for the differences between the two documents, there are better ways (eg Tools|Merge Documents or
a
macro that simply goes though each para looking for & highlighting the differences).

--
Cheers
macropod
[Microsoft MVP - Word]


bruno said:
My need is to combine two long Word documents (with many footnotes) side by
side in two columns of one table. Excel, because it facilitates paragraph
alignment.
 
B

bruno

wow, excellent, it does exactly what I imagined. Thank you very much, Pesach.

As to further steps, i will be happy to follow your invitation in the near
future.

Concerning this present step, there are just two details I have to add:
1. Before running the macro I have to make sure, that at the end of the
document there is an empty para with standard formatting, otherwise the first
footnote might eventually be added to the last para. To do this I would use
the following code:
/---------------
With ActiveDocument.Sections.Last.Range
.Collapse Direction:=wdCollapseEnd
.InsertParagraphAfter
Selection.EndKey Unit:=wdStory
Selection.ClearFormatting
End With
---------------/

2. The footnotes might contain TABs after the footnote number which disturbs
in the further process. To replace these TABs with hard spaces I would use
this code (obtained with the macro recorder):
/---------------
If ActiveWindow.ActivePane.View.Type = wdPrintView Or ActiveWindow. _
ActivePane.View.Type = wdWebView Or
ActiveWindow.ActivePane.View.Type = _
wdPrintPreview Then
ActiveWindow.View.SeekView = wdSeekFootnotes
Else
ActiveWindow.View.SplitSpecial = wdPaneFootnotes
End If
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^t"
.Replacement.Text = "^s"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
If ActiveWindow.ActivePane.View.Type = wdPrintView Or ActiveWindow. _
ActivePane.View.Type = wdWebView Or
ActiveWindow.ActivePane.View.Type = _
wdPrintPreview Then
ActiveWindow.View.SeekView = wdSeekMainDocument
Else
ActiveWindow.Panes(2).Close
End If
---------------/






--
bruno


Pesach Shelnitz said:
Hi Bruno,

The following macro inserts a superscripted number at the location of each
footnote, copies the text to a list at end of the document, and deletes the
foonotes. Note that in this simple version the footnotes will be numbered 1,
2, 3, etc. regardless of the original numbering and that the footnote text
will be copied without formatting.

Sub ConvertFootnotesToList()

Dim num As Long
Dim myString As String

If ActiveDocument.Footnotes.Count = 0 Then
MsgBox "There are no footnotes in this document."
Exit Sub
End If
With Selection
.HomeKey wdStory
For num = 1 To ActiveDocument.Footnotes.Count
.GoToNext wdGoToFootnote
.Font.Superscript = True
.TypeText Text:=CStr(num)
.Font.Superscript = False
.Expand wdWord
With ActiveDocument.Footnotes(1)
myString = myString & CStr(num) & _
". " & .Range.Text & vbCrLf
.Delete
End With
Next
.EndKey wdStory
.InsertAfter myString
.Collapse Direction:=wdCollapseEnd
End With
End Sub

If this macro does what you want, I suggest that you start a new thread and
explain what you want to do next. I agree with the others that you should be
able to do what you want in Word without moving over to Excel and back.

--
Hope this helps,
Pesach Shelnitz


Peter T. Daniels said:
Me, I've never used VBA for anything. Why do you want to make it so
complicated??

What can an Excel table do with text that a Word table can't?

So you, macropod and Peter, suggest to do all of it "simply" in Word.

But isn't my question just concerning a VBA macro in Word ?
If it is so simple why don't you have a look at it and tell me what is wrong
with it?

Well, anyhow, thank you for bothering.
--
bruno



:
Hi Bruno,

I can't see how Excel helps paragraph alignment any better than a Word table (which you can split at paragraph breaks).

In any event, if you're looking for the differences between the two documents, there are better ways (eg Tools|Merge Documents or a
macro that simply goes though each para looking for & highlighting the differences).

--
Cheers
macropod
[Microsoft MVP - Word]

My need is to combine two long Word documents (with many footnotes) side by
side in two columns of one table. Excel, because it facilitates paragraph
alignment.
 
B

bruno

Hi macropod,

what you describe is more or less how i tried to do it first, some time ago
when I just had started working with Word. But the 2-in-one-document was too
complex for me to handle in Word: heading styles, para numbering, footnotes
etc. (may be i simply was too inexperienced).

To get it done i then tried to copy the word table to Excel and here I liked
the result: the text formatting was still there, the para-number styles were
broken but the numbers appeared as text, which is ok. Only the footnotes
caused problems, i did not know how to break them. But thanks to the macro of
Pesach this is now solved.

So, doing it via Excel for me is a valuable work around as i don't know how
to manage it all in Word.

regards,
bruno


--
bruno


macropod said:
Hi bruno,

Why? Because you don't need the macro if you're doing it in Word.

To do the comparison in Word:
1. Select the 1st document and convert its contents to a table, using the paragraphs as the text separators.
2. Reduce the column width to half the page width
3. Repeat steps 1 & 2 for the 2nd document
4. Copy the table from one of the documents
5. In the other document, place the insertion point at the end-of-row marker for the 1st row in the table, then paste the other
table there.

You now have a two-column table containing the contents of both documents. The footnotes from both will also be interspersed, for
ease of comparison.

If you find yourself in a situation where the paragraphs get out of synch because of differences between the documents, it's a
simple matter to insert one or more cells into whichever column requires it to restore the synchronisation.

--
Cheers
macropod
[Microsoft MVP - Word]


bruno said:
So you, macropod and Peter, suggest to do all of it "simply" in Word.

But isn't my question just concerning a VBA macro in Word ?
If it is so simple why don't you have a look at it and tell me what is wrong
with it?

Well, anyhow, thank you for bothering.
--
bruno


macropod said:
Hi Bruno,

I can't see how Excel helps paragraph alignment any better than a Word table (which you can split at paragraph breaks).

In any event, if you're looking for the differences between the two documents, there are better ways (eg Tools|Merge Documents or
a
macro that simply goes though each para looking for & highlighting the differences).

--
Cheers
macropod
[Microsoft MVP - Word]


My need is to combine two long Word documents (with many footnotes) side by
side in two columns of one table. Excel, because it facilitates paragraph
alignment.
 

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