Tuesday, May 31, 2011

Some Helpful Word Macros

Step 1. Be a user of Windows XP and Microsoft Word 2003. This is not open for debate.

Step 2. From the menus at the top of the MS Word window, pull down "Tools," then select "Macro," then "Record New Macro." Type a distinctive name for a macro; then, under "Assign Macro To," press the "Keyboard" button. Type an unassigned keyboard shortcut (examples will be given later), then click "Assign" and "Close." Then immediately press the "Stop" button on the floating Macro Recorder control. Repeat, substituting different macro names and keyboard shortcuts, until you have created a blank "placeholder" macro for each of the macros below.

Step 3. Pull down the "Tools" menu, then select "Macro," then "Macros," then click the "Edit" button to open up the Microsoft Visual Basic editor, in which you can edit the code for all the macros in your Normal template. Copy the following paragraphs of code and paste each section of code under the appropriate macro name, after the lines "Sub [MACRO NAME]," "[MACRO NAME] Macro," and "Macro recorded [DATE] by [USER]," but before the line that says "End Sub."

And now some macros that I think you may find useful. I give first the name I suggest assigning to each macro, then a nice eligible keyboard shortcut, and finally the code to paste into Virtual Basic.

HEADER: To put the filename, path, and page number in a hairline box at the top of each page of a Word document:
Macro Name: Header
Hot Key: ctrl+. (Hold "ctrl" key and type a period.)
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Application.DisplayAutoCompleteTips = True
NormalTemplate.AutoTextEntries("Filename and path").Insert Where:= _
Selection.Range, RichText:=True
Selection.TypeParagraph
Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
Selection.TypeParagraph
Selection.WholeStory
With Selection.Borders(wdBorderTop)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderLeft)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderRight)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ROUGH: To add the effect of a rubber stamp saying "ROUGH #1" to the top of the page (which can be edited after being inserted to show whatever Rough Number you want):
Macro Name: Rough
Hot Key: ctrl+;
ActiveDocument.Shapes.AddTextEffect(msoTextEffect2, "ROUGH #1" & Chr(13) & "" & Chr(10) & "__ Approved by KS", _
"Arial Black", 24#, msoFalse, msoFalse, 232.1, 107.25).Select
Selection.ShapeRange.TextEffect.PresetShape = msoTextEffectShapeSlantDown
Selection.ShapeRange.WrapFormat.Type = wdWrapTight
Selection.ShapeRange.ScaleWidth 0.62, msoFalse, msoScaleFromBottomRight
Selection.ShapeRange.ScaleHeight 0.75, msoFalse, msoScaleFromTopLeft
PASTE NO FORMAT: To paste from the clipboard without keeping the format of the document it was copied from (i.e., without changing the format of the insertion point):
Macro Name: PasteNoFormat
Hot Key: alt+v
Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine, DisplayAsIcon:=False
FLIP QUOTE MARKS: When, after pasting a section of text copied from another document, you need to change all the double-quotes into single and all the single-quotes into double:
Macro Name: ReverseQuotes
Hot Key: alt+' (apostrophe)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "'"
.Replacement.Text = "@@"
.Forward = True
.Wrap = wdFindAsk
.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 = """"
.Replacement.Text = "'"
.Forward = True
.Wrap = wdFindAsk
.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 = "@@"
.Replacement.Text = """"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
NOTE: You may have some trouble with apostrophes on this one.

BLOCK QUOTE MARGINS: To indent both right and left margins of the selected paragraph by 0.5 inches:
Macro Name: BlockQuoteMargins
Hot Key: alt+b
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
FOOTNOTE: To insert a footnote, placing the reference number at the insertion point:
Macro Name: Footnote
Hot Key: alt+i
With ActiveDocument.Range(Start:=ActiveDocument.Content.Start, End:= _
ActiveDocument.Content.End)
With .FootnoteOptions
.Location = wdBottomOfPage
.NumberingRule = wdRestartContinuous
.StartingNumber = 1
.NumberStyle = wdNoteNumberStyleArabic
End With
.Footnotes.Add Range:=Selection.Range, Reference:=""
End With
COLUMN BREAK: When typing on a page formatted in two or more columns, to insert a hard column break at the insertion point:
Macro Name: ColumnBreak
Hot Key: alt-/
Selection.InsertBreak Type:=wdColumnBreak
EXTREME EMPHASIS: To convert selected text into all caps, bold type, and word-only underline:
Macro Name: BoldCapUnderline
Hot Key: alt+;
Selection.Font.Bold = wdToggle
If Selection.Font.Underline = wdUnderlineWords Then
Selection.Font.Underline = wdUnderlineNone
Else
Selection.Font.Underline = wdUnderlineWords
End If
Selection.Font.AllCaps = wdToggle
LIGHT YELLOW SHADING: To create a "yellow highlighting" effect over the selected text, one that leaves the text looking very readable when printed on a color laserjet:
Macro Name: YellowShading
Hot Key: alt+1
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = wdColorLightYellow
LIGHT GREEN SHADING: Ditto, only with a green highlighting effect:
MacroName: GreenShading
Hot Key: alt+2
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = wdColorLightGreen
LIGHT BLUE SHADING: Ditto, only with a blue highlighting effect (which, I find, is easier to see on paper than on the monitor):
MacroName: BlueShading
Hot Key: alt+3
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = wdColorLightTurquoise
ORANGE SHADING: Ditto, only rather like an orange highlighter:
MacroName: OrangeShading
Hot Key: alt+4
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = wdColorTan
PINK SHADING: Ditto, only with pink highlighting:
Macro Name: PinkShading
Hot Key: alt+5
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = 16764159
PURPLE SHADING: Ditto, only with purple highlighting:
Macro Name: PurpleShading
Hot Key: alt+6
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = 16764108
NOTE: I'm sure these "shading" macros can be tweaked to suit the color calibration of your monitor and/or printer. I recorded them so that I could "flag" paragraphs of research material for up to 6 different topics of interest.

RED BOLD: To change a selection from regular type to bold, red type:
Macro Name: RedBold
Hot Key: alt+7
Selection.Font.Bold = wdToggle
With Selection.Font
.Name = "Times"
.Size = 12
.Bold = True
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorRed
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
GREEN BOLD: To achieve the same effect, only with green type:
Macro Name: GreenBold
Hot Key: alt+8
Code: The same except, where RedBold says "wdColorRed," change it to "wdColorGreen."

BLUE BOLD: Ditto, only with blue type:
Macro Name: BlueBold
Hot Key: alt+9
Code: The same as RedBold, only replace "wdColorRed" with "wdColorBlue."

PINK BOLD: Ditto, only with pink type:
Macro Name: PinkBold
Hot Key: alt+0
Code: The same as RedBold, only replace "wdColorRed" with "wdColorPink"

NOTE: These colored types can be handy, for example, when you have to edit copy & you want to draw attention to text you recommend deleting, to your suggested rewrite, to new material you would like to see added, or to wordings proposed by different editors, translators, etc.

Two more shortcuts have proven very handy to me. I work in a variety of applications, some of which have one sort of keyboard shortcuts for an em-dash or an en-dash, and some another. As I move between these programs, I find it most difficult to keep in mind which shortcut I have to use; in some cases, guessing incorrectly leads to disaster. So, I've created my own customization. I recommend that you do too.

EM and EN DASH: From the "Insert" menu, choose "Symbol," scroll through the character map of your default font until you find the em dash (and likewise for the en dash). Once that character is selected, click "Shortcut Key," then assign alt+m for the em dash, and alt+n for the en dash, then click "Close" and "Cancel." Then it's just a matter of remembering how to use them. Use the em dash instead of two hyphens to indicate a break in a sentence; use the en dash instead of a hyphen to indicate a range of dates, page numbers, etc.

NUMBERING: From the "Tools" menu, choose "Customize," then "Keyboards," then under Categories select "Format," and under Commands select "FormatNumberDefault." Under Press New Shortcut Key, press alt+l (lowercase L), then click "Close" twice. This will insert a numbered list without requiring you to hunt through the menus for it.

These are only some of the macros that have saved me tons of keystrokes and mouse-clicks in the last five or six years. May they come in handy for you!

P.S.: Upon request, I can also give you some handy tips on how to transfer macros, autotext, etc. from your normal template to another user's ditto. This can come in especially handy in a shared-folder type of workspace, where different workers are doing similar things and need access to the same shortcuts.

1 comment:

Robbie F. said...

My other macros include ones to: 1) indent the margins so as to fit in the printable area of a 3x5 card; 2) add a footer saying "Subject: CC: BCC: Attachments:" so the author of a draft email can fill in those details; 3) add a footer saying "SNAIL MAIL--Enclosures:" so they aren't forgotten when the letter is ready to send; and 4) add a header or footer with miniature letterhead (return address, email & phone number) that can be easily added to any document.

Perhaps of less widespread application, but very difficult to create so I mention them with pride, are two macros I created to assist in repetitive tasks arising from the unique circumstances of my work. One of them inserts a particular image file (JPEG) into a Word document; I only wish I could teach this macro to set the JPEG's "wrapping style" to "tight" or "in front of text," but so far I haven't succeeded in this. The other special macro switches to a R-to-L Hebrew font and resolves a couple of paragraph style & format issues that pop up every time you do this.

Finally, let me also sing the praises of AutoText, a feature that later versions of Word (post 2003) either dispense with or make impractically difficult to get at. Also shareable from one user to another, AutoTexts can be set up to enable you, in as few as 3 or 4 keystrokes, to call up the correct spelling of a difficult word or name ("Ekaterinberg," for example), the full bibliographic citation of a book, the "full inside address" of someone you would write a letter to, or a favorite quotation with indented margins and a short-form citation at the end. It helps to maintain a table, also doable in Word, to keep track of these AutoTexts as they are added, deleted, and updated.