Batch Format Decision Letters In Word
  • 01 Apr 2024
  • 2 minute read
  • Dark
    Light
  • PDF

Batch Format Decision Letters In Word

  • Dark
    Light
  • PDF

Article Summary

Getting Started

To batch format your letters, you’ll need to create a VBA macro. You can use the macro indefinitely after you set it up. Three examples include:

Appending Images

Modifying font

Adjusting page properties

to a header

to a signature

names

sizes

colors

margins

  1. To retrieve your letters from Slate, create and run a query, and select Decision Letter Export to Word under Output.

  2. In Microsoft Word, press Alt+F11 to access the editor.

  3. Begin by entering the following code:

    Sub cleanLetters()
    
         Selection.WholeStory
    
    End Sub

Appending Images

Appending Images to a Header

To append an image to a header, add the following code after Selection.WholeStory and before End Sub:

'Append image to header

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
 With Dialogs(wdDialogInsertPicture)
      .Name = "http://i.imgur.com/hHCIojS.png" 'This is the URL for the header image
      .Execute
 End With

Appending Signature Image to a Signature

To append a signature image to a signature line, add the following code after Selection.WholeStory and before End Sub:

'Append signature image to signature
 Selection.Find.Replacement.ClearFormatting
 With Selection.Find
      .Text = "The Jacksonville University Admissions Team" ' This is the name we're looking for, and it shouldn't exist in the rest of the letter (e.g., in the body)
      Do While .Execute
           With Dialogs(wdDialogInsertPicture)
                .Name = "http://i.imgur.com/x7YxZjv.png" 'This is the URL for the signature
                .Execute
           End With
      Loop
      .Text = "[email protected]" ' Because we replaced the name with the signature, we need to find the unique text that immediately proceeded the name
      .Replacement.Text = "Alexander Hamilton^[email protected]" ' In this case, we're replacing the email address with "Alexander Hamilton" and then adding the email address to the next line
      .Forward = True
      .Wrap = wdFindContinue
      .MatchCase = True
 End With
 Selection.Find.Execute Replace:=wdReplaceAll

Changing Font Name, Font Size, or Font Color

To change font name, font size, or font color, add the following code after Selection.WholeStory and before End Sub:

'Modify font & font size

Selection.Font.Name = "Times New Roman"

Selection.Font.Size = 12

Selection.Font.Color = wdColorAutomatic

Changing Page Properties

To change page properties (such as margins), add the following code after Selection.WholeStory and before End Sub:

'Modify margins by inches

With ActiveDocument.PageSetup

    .TopMargin = InchesToPoints(2)

    .BottomMargin = InchesToPoints(0.75)

    .LeftMargin = InchesToPoints(0.5)

    .RightMargin = InchesToPoints(0.5)

    .HeaderDistance = InchesToPoints(1) 'Distance between the header and top of the page

    .FooterDistance = InchesToPoints(1) 'Distance between the footer and bottom of the page

    .PageWidth = InchesToPoints(8.5) 'Paper width

    .PageHeight = InchesToPoints(11) 'Paper height

End With

Saving the Macro

  1. Save the macro by selecting File > Export File.

  2. Right-click Modules under Normal and select Import File. Select your macro file.

  3. To run your macro, select the icon.

    Step3.gif

Tip

A test letter (Test Letter.docx) and a macro file (Test Macro.bas) are attached for your experimentation and use:

Attachments

Was this article helpful?