Code

I have placed all the code snippets from the book here and then some. Copy them into the a macro in the Microsoft Visual Basic editor between the Sub and End Sub lines. For detailed steps to create a macro, see Creating a Paste Unformatted macro in chapter 1.5 of the book.

Converting All Footnotes to Text (Chapter 7.2.3)

posted May 2, 2014, 9:59 AM by Wolf O'Rourc   [ updated May 5, 2014, 2:29 PM ]

Since self-publishing programs do not take kindly to Word footnotes, you need to convert all of them to text. One way is to convert them all to endnotes, then copy them to text. Word provides functions to convert all footnotes to endnotes and vice-verse.

AR: Click References | Footnotes dialog launcher (the tiny arrow in the bottom right corner of the Footnotes group.
BR: Click Insert | Reference | Footnotes.
In the Footnote and Endnote dialog box click [Convert].
Click the a radio button to convert footnotes to endnotes, endnotes to footnotes, or converting both to the other at the same time by clicking Swap footnotes and endnotes.


You can convert endnotes to text as described in chapter 7.2.3. If, instead, you want to change all footnotes to in-line text, the following code from techsupportforum.com will do the trick.

Sub ConvertFootNotesToText()

Dim afootnote As Footnote

ActiveDocument.Range.InsertParagraphAfter
Selection.GoTo What:=wdGoToLine, Which:=wdGoToLast
Selection.GoTo What:=wdGoToBookmark, Name:="\Para"
Selection.Style = wdStyleNormal
ActiveDocument.GoTo What:=wdGoToLine, Which:=wdGoToFirst
For Each afootnote In ActiveDocument.Footnotes
  Selection.GoTo What:=wdGoToFootnote, Count:=afootnote.Index
  Selection.GoTo What:=wdGoToBookmark, Name:="\HeadingLevel"
  Selection.MoveEnd Unit:=wdCharacter, Count:=-1
  Selection.Collapse Direction:=wdCollapseEnd
  Selection.Range.InsertAfter _
    vbCr & "x" & afootnote.Index & "x " & afootnote.Range
  Selection.GoTo What:=wdGoToLine, Which:=wdGoToNext
  Selection.GoTo What:=wdGoToBookmark, Name:="\Para"
  Selection.Style = wdStyleNormal
    afootnote.Reference.InsertBefore "x" & afootnote.Index & "x"
Next afootnote

For Each afootnote In ActiveDocument.Footnotes
  afootnote.Reference.Delete
Next afootnote

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
  .Superscript = True
End With

With Selection.Find
  .Text = "(x)([0-9]{1,})(x)"
  .Replacement.Text = "\2"
  .Forward = True
  .Wrap = wdFindContinue
  .Format = True
  .MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

ActiveDocument.GoTo What:=wdGoToLine, Which:=wdGoToFirst
End Sub
Depending on your regional settings the separator for wildcard occurrences may be a semi-colon. If the at the end you are left with reference numbers surrounded by "x," try "{1;}" instead of "{1,}."

Paste Unformatted macro (Chapter 1.5)

posted Feb 10, 2014, 3:25 PM by Wolf O'Rourc

Selection.PasteSpecial Link:=False, DataType:=20,
    Placement:=wdInLine, DisplayAsIcon:=False

Cut To comma macro (Chapter 1.5)

posted Feb 10, 2014, 3:22 PM by Wolf O'Rourc

With Selection
.Extend Character:=","
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
Selection.Cut

Macro to go back to the last location (Chapter 1.6.3)

posted Feb 10, 2014, 3:11 PM by Wolf O'Rourc   [ updated Feb 10, 2014, 3:19 PM ]

Sub AutoOpen()
Application.GoBack
End Sub

Macro to go back to the last location (Word 2007/10) (Chapter 1.6.3)

posted Feb 10, 2014, 3:08 PM by Wolf O'Rourc   [ updated Feb 10, 2014, 3:18 PM ]

If Application.GoBack does not work in your version of Word, you can still return to the last location you edited when you reopen the document by using a bookmark. The AutoClose macro saves the current location as a bookmark when you close a document. The AutoOpen macro then jumps to that bookmark on open. The code was developed by Edward Mendelson and published in PC Magazine at
http://www.pcmag.com/article2/0,2817,2329214,00.asp

Sub AutoClose()
On Error Resume Next
If ActiveDocument.Words.Count > 1 Then
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="LastEditPosition"
    End With
End If
End Sub

Sub AutoOpen()
On Error Resume Next
If ActiveDocument.Bookmarks.Exists("LastEditPosition") = True Then
    Selection.GoTo What:=wdGoToBookmark, Name:="LastEditPosition"
End If
End Sub

If you do not like the prompting to save the file on close, you can follow the practice of Graham Mayor and save the bookmark whenever the document is saved, as done in the following code. See the post in the Office Community at
http://answers.microsoft.com/en-us/office/forum/office_2007-word/how-to-make-word-2007-remember-last-positionpage/54299522-52f1-4b50-a4e1-c4689b3b8018

Sub FileSave()
On Error Resume Next
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="LastEditPosition"
ActiveDocument.Save
End Sub

Sub FileSaveAs()
On Error Resume Next
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="LastEditPosition"
Dialogs(wdDialogFileSaveAs).Show
End Sub

FARM macro for general replace (Chapter 3.2)

posted Feb 10, 2014, 2:39 PM by Wolf O'Rourc   [ updated Feb 10, 2014, 2:42 PM ]

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = "#cc"
    .Replacement.Text = "Cathrine Carlisle"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchByte = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
    .Text = "#dp"
    .Replacement.Text = "Deborah Perry"
End With

Selection.Find.Execute Replace:=wdReplaceAll

FARM macro for whole-word replace (Chapter 3.2)

posted Feb 10, 2014, 2:37 PM by Wolf O'Rourc

With Selection.Find
    .Text = "cld"
    .Replacement.Text = "could"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWholeWord = True
    .MatchByte = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With

Selection.Find.Execute Replace:=wdReplaceAll

FARM macro for replace down (Chapter 3.2)

posted Feb 10, 2014, 2:31 PM by Wolf O'Rourc

With Selection.Find
    .Text = "xdc"
    .Replacement.Text = "Washington, DC"
    .Forward = True
    .Wrap = WdFindStop
    .Format = False
    .MatchWholeWord = True
    .MatchByte = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

1-8 of 8