Modify all endnotes (Word 2007)

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Modify all endnotes (Word 2007)

Post by Sundog »

A user wants to make a change to all endnotes, along the lines of this macro:

Code: Select all

Sub EndnoteTab()
'
' EndnoteTab Macro
' Adds a tab after the space that follows the endnote reference no. in the Endnotes section of the document.
'
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Endnote Reference")
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=2
    Selection.TypeText Text:=vbTab
End Sub
Refresh my memory (I've been away, getting a shoulder replaced) as to how to start at the top of the Endnote section and apply this macro for each endnote, then exit when there are no more endnotes.

Thanks for any help to get me back up to speed!
Sundog

User avatar
HansV
Administrator
Posts: 79697
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Modify all endnotes (Word 2007)

Post by HansV »

I hope the surgery helped and that you're recovering well!

Try this version:

Code: Select all

Sub EndnoteTab()
'
' EndnoteTab Macro
' Adds a tab after the space that follows the endnote reference no. in the Endnotes section of the document.
'
    With Selection.Find
        .ClearFormatting
        .Style = ActiveDocument.Styles("Endnote Reference")
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        Do While .Execute
            Selection.MoveRight Unit:=wdCharacter, Count:=2
            Selection.TypeText Text:=vbTab
        Loop
    End With
End Sub
Best wishes,
Hans

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Modify all endnotes (Word 2007)

Post by Sundog »

Got it in one! Thanks, Hans.

Recovery: I can't do this at arms length yet :cheers:, but it seems to taste the same if I keep my elbow bent.
Sundog