Monday, March 3, 2014

USE A MACRO TO ADD YOUR LETTERHEAD TO A DOCUMENT

Previously, we explained how to create an officewide letterhead template so that everyone in your office would always use the same letterhead and updating it could be done one time and everyone would get the update. Today, let's take that idea one step farther and create a macro that will put the letterhead on your open document.

The comments in the macro explain exactly how and why the macro works. For those not interested in why the macro works, running the macro on an open document will create a new file with the text of your open document but the header and footer of your letterhead template.

The blue, courier text below is the entirety of the macro. The only customization required is inserting the path and file name of your letterhead template in the red text below. For example, if your letterhead template was called letterhead.dotm and was stored in a folder on your c:\ drive called templates, then you would replace the red text with c:\templates\letterhead.dotm.

Sub LetterHead()
'
' Letterhead Macro
' add letterhead to existing document
' Joshua Goodwin 2012
'

'copy current document
Selection.WholeStory
Selection.Copy

'close current document without saving
ActiveDocument.Close (wdDoNotSaveChanges)


' define path and filename for letter head template

Dim LetterHead As String

LetterHead = "replace red text with path and filename for your letterhead template"

' open letterhead template
Documents.Add Template:= _
        LetterHead, _
        NewTemplate:=False, DocumentType:=0

'paste into letterhead
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.PasteAndFormat (wdFormatOriginalFormatting)

End Sub

3 comments:

  1. Excellent.

    Thank you.

    ReplyDelete
  2. I used the macro but it throws the letterhead into the middle of my existing document. Around page 14. Is there a reason that could happen?

    ReplyDelete