1

I have a Microsoft Word document that has slightly over 600 numbered / bulleted lines (i.e., paragraphs).  Something like this:

  1. Once upon a midnight dreary, while I pondered, weak and weary,¶
  2. Over many a quaint and curious volume of forgotten lore--¶
  3. While I nodded, nearly napping, suddenly there came a tapping,¶
  4. As of some one gently rapping--rapping at my chamber door.¶
  5. "'Tis some visitor," I muttered, "tapping at my chamber door--¶
  6. Only this and nothing more."¶

Source: The Raven by Edgar Allan Poe, copied from Project Gutenberg.

... or it could be bulleted; I can switch between those two formats easily enough.

I'd like to reformat it as an essay – not 600 separate lines – removing the numbers or bullets, and attach a footnote (with numbers as superscripts) to each line (as currently formatted).  Something like this:

Once upon a midnight dreary, while I pondered, weak and weary,1 Over many a quaint and curious volume of forgotten lore--2 While I nodded, nearly napping, suddenly there came a tapping,3 As of some one gently rapping--rapping at my chamber door.4 "'Tis some visitor," I muttered, "tapping at my chamber door--5 Only this and nothing more." 6 ¶

________________________
1
2
3
4
5
6

The footnotes should be blank, allowing me to write the footnote text later.  Footnote numbers may be assigned sequentially, without regard to the current numbers on the paragraphs – but you may assume that the paragraphs are correctly numbered sequentially, with no skipped or repeated numbers, or other special instances.

Dov
  • 13

1 Answers1

0

Insert the following VBA routine.  Then, click at the beginning of the file and run the routine.

Sub Reformat()
    With Selection
        With .Find
            .ClearFormatting
            .MatchWildcards = True
            .Text = "[!^13]^13"
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
        End With
        With .FootnoteOptions
            .Location = wdBottomOfPage
            .NumberingRule = wdRestartContinuous
            .StartingNumber = 1
            .NumberStyle = wdNoteNumberStyleArabic
            .LayoutColumns = 0
        End With
        Do While True
            .Find.Execute
            If Not .Find.Found Then Exit Do
            .MoveLeft Unit:=wdCharacter, Count:=1
            .Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
            .MoveRight Unit:=wdCharacter, Count:=1
            .Footnotes.Add Range:=.Range, Reference:="", Text:=""
            .MoveRight Unit:=wdCharacter, Count:=1
            .TypeText Text:=" "
            .Delete Unit:=wdCharacter, Count:=1
        Loop
    End With
End Sub

See How do I add VBA in MS Office? for general guidance on how to do that.

Parts of the above code were actually generated automatically by Microsoft Word.  I don’t fully understand every line, and I suspect that some of them can just be left out.  Here are a few that I can explain:

  • .MatchWildcards = True and .Text = "[!^13]^13".  These define what to look for in the text.  Wildcard mode gives you more power.  In wildcard mode, ^13 represents a paragraph break.  This is typically generated by pressing Enter and, in Word’s Show Hidden Characters mode, appears as ¶.

    [! character(s) ] matches any character other than one of the ones between the [! and the ].  So [!^13] matches any character other than a paragraph break.  Put them together and [!^13]^13 matches a paragraph mark preceded by an ordinary character — in other words, the end of a non-empty paragraph.

  • .Wrap = wdFindStop.  When you get to the end of the document, stop (don’t continue from the beginning).
  • .StartingNumber = 1.  I guess this means that the first footnote created will be #1, the second one to be created will be #2, and so on.  (The footnote numbers will not be based on the existing paragraph numbers.)
  • Do While True — run an “infinite” loop.
  • .Find.Execute — find the next paragraph mark.
  • If Not .Find.Found Then Exit Do — if we don’t find one, break out of the loop.
  • .MoveLeft Unit:=wdCharacter, Count:=1 — move to the left of the last character of the paragraph.  I expect that this will be a punctuation mark (e.g., ., ! or ?).
  • .Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph — format the paragraph to be normal, not numbered or bulleted.  This might really be necessary only for the first paragraph, but there’s no harm in leaving it in the loop and executing it on every iteration.
  • .MoveRight Unit:=wdCharacter, Count:=1 — move to the right of the last character of the paragraph (which might be a punctuation mark).
  • .Footnotes.Add Range:=.Range, Reference:="", Text:="" — insert a footnote with no text.
  • .MoveRight Unit:=wdCharacter, Count:=1 — move to the right of the footnote number.
  • .TypeText Text:=" " — add a space after the footnote number.  (You might want to change this to be two spaces.)
  • .Delete Unit:=wdCharacter, Count:=1 — delete the paragraph mark.

I ran the above on this input:

before

and got this result:

after

Note: This takes in excess of one second per paragraph to execute.  For a 600-paragraph document, that’s over ten minutes.  The screen might appear to freeze, and Word may show as “Not responding”, while the macro is running.  So, if you have other Word windows open, you might want to close them, or at least save them.  And then be patient.