User:DR-CORDULIA/Resources/Formatting Macro
Jump to navigation
Jump to search
Formatting Macro for Word
This Microsoft Word macro formats text to improve compatibility with DR and compliance with DR’s standard of putting two spaces between sentences. The macro will:
- replace tabs with word spaces
- delete excess word spacing (three or more spaces)
- ensure there is only one space between words
- ensure there are two spaces between sentences
- replace curly quotes and apostrophes (known as “smart quotes” in Word) with straight quotes
- replace em dashes (—) with typewriter approximations (--)
- replace en dashes (–) with typewriter approximations (-)
- replace ellipses (…) with typewriter approximations (...)
How to install this macro:
- In Microsoft Word, click View the view tab on the ribbon.
- Click “Macros.”
- Where it says “Macro name,” type “Typewriter.”
- Click “Create.”
- Copy and paste this macro, overwriting the entire section that begins with “Sub Typewriter()” and ends with “End Sub.”
- In the File menu, select “Save Normal.”
How to assign a keyboard shortcut to this macro:
- In Microsoft Word, go to File → Options → Customize Ribbon.
- Where it says “Keyboard Shortcuts,” Click “Customize.”
- Near the bottom of the “Categories” menu, select “Macros.”
- You should see your new Typewriter macro listed to the right. Select it.
- Put your cursor in the box that says “Press new shortcut key.”
- Input the desired hotkey. I recommend using something that Word has not already assigned to another function. (I use Shift+F8.)
- Click “Close.”
Sub Typewriter() ' ' Typewriter Macro ' ' Selection.HomeKey Unit:=wdStory With Options .AutoFormatAsYouTypeApplyHeadings = False .AutoFormatAsYouTypeApplyBorders = True .AutoFormatAsYouTypeApplyBulletedLists = False .AutoFormatAsYouTypeApplyNumberedLists = True .AutoFormatAsYouTypeApplyTables = True .AutoFormatAsYouTypeReplaceQuotes = False .AutoFormatAsYouTypeReplaceSymbols = False .AutoFormatAsYouTypeReplaceOrdinals = False .AutoFormatAsYouTypeReplaceFractions = False .AutoFormatAsYouTypeReplacePlainTextEmphasis = False .AutoFormatAsYouTypeReplaceHyperlinks = False .AutoFormatAsYouTypeFormatListItemBeginning = True .AutoFormatAsYouTypeDefineStyles = False .TabIndentKey = True End With With AutoCorrect .CorrectInitialCaps = False .CorrectSentenceCaps = False .CorrectDays = False .CorrectCapsLock = True .ReplaceText = True .ReplaceTextFromSpellingChecker = False .CorrectKeyboardSetting = False .DisplayAutoCorrectOptions = True .CorrectTableCells = False End With With Options .AutoFormatApplyHeadings = True .AutoFormatApplyLists = True .AutoFormatApplyBulletedLists = False .AutoFormatApplyOtherParas = True .AutoFormatReplaceQuotes = False .AutoFormatReplaceSymbols = False .AutoFormatReplaceOrdinals = False .AutoFormatReplaceFractions = False .AutoFormatReplacePlainTextEmphasis = False .AutoFormatReplaceHyperlinks = False .AutoFormatPreserveStyles = True .AutoFormatPlainTextWordMail = True End With Options.LabelSmartTags = False With Selection.Find .Text = "^t" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = " " .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "'" .Replacement.Text = "'" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = """" .Replacement.Text = """" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ". " .Replacement.Text = ". " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "."" " .Replacement.Text = "."" " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ".' " .Replacement.Text = ".' " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = ".) " .Replacement.Text = ".) " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "."") " .Replacement.Text = "."") " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "? " .Replacement.Text = "? " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "?"" " .Replacement.Text = "?"" " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "?' " .Replacement.Text = "?' " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "?) " .Replacement.Text = "?) " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "?"") " .Replacement.Text = "?"") " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "! " .Replacement.Text = "! " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "!"" " .Replacement.Text = "!"" " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "!' " .Replacement.Text = "!' " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "!) " .Replacement.Text = "!) " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "!"") " .Replacement.Text = "!"") " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "—" .Replacement.Text = " -- " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "–" .Replacement.Text = "-" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = " --" .Replacement.Text = " --" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "-- " .Replacement.Text = "-- " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "…" .Replacement.Text = " ... " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = " ..." .Replacement.Text = " ..." .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "... " .Replacement.Text = "... " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = " " .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll End Sub