Word

Footer with Path and File name, Date and Time

Ease of Use

Intermediate

Version tested with

 

Submitted by:

JOrzech

Description:

This macro will insert a footer into your document which contains the path and file name, as well as the current date and time. When the document is moved, the footer automatically updates. 

Discussion:

This macro allows you to track the location of a document, whether it's stored on a hard drive or on a network. If the document is moved, the location will automatically update so you will always know where your document resides. If you like this macro, consider learning how to record macros. This is a very simple macro that you could record yourself, and use over and over in many different documents. 

Code:

instructions for use

			

Sub AddFooter() ' View footer 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 If Selection.HeaderFooter.IsHeader = True Then ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter Else ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader End If 'change font to 8 point Selection.Font.Size = 8 'insert filename and path via autotext NormalTemplate.AutoTextEntries("Filename and path").Insert Where:= _ Selection.Range Selection.TypeParagraph 'insert current date and time Selection.InsertDateTime DateTimeFormat:="M/d/yyyy h:mm am/pm", _ InsertAsField:=True, DateLanguage:=wdEnglishUS, CalendarType:= _ wdCalendarWestern, InsertAsFullWidth:=False 'close footer window ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument End Sub

How to use:

  1. Hit Alt+F11 to open the Visual Basic Editor (VBE).
  2. Make sure Project Explorer is visible (View, Project Explorer)
  3. Double-click on Normal (or normal.dot) at the left of the window.
  4. Insert, Module and paste this code into the window at right.
  5. Hit the Save toolbar button and close the VBE.
  6. Hit Alt+F11 to return to Word.
  7. Exit Word. If you're asked to save normal.dot, say yes.
 

Test the code:

  1. Open a blank document.
  2. Hit Tools-Macro-Macros, and double-click AddFooter.
 

Sample File:

No Attachment 

Approved by Anne Troy


This entry has been viewed 127 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express