Group: microsoft.public.word.vba.general
From: =?Utf-8?B?SmVhbi1HdXkgTWFyY2ls?=
Date: Friday, February 15, 2008 2:41 PM
Subject: RE: How do I put this into a Footer



"Office_Novice" wrote:

> I would like to insert the UserName FormField into footer programmatically.
>
> this code works but can i get it into a footer?
>
> Selection.Collapse Direction:=wdCollapseStart
> Set myField = ActiveDocument.Fields.Add(Range:=Selection.Range, _
> Type:=wdFieldUserName)
>

It depends on the structure of your document.
There are three types of footers, and your document may have more than one
section.

Let's assume you want that in the main footer of the first section:

Option Explicit

Sub InsertFieldFooter()

Dim myField As Field
Dim rgeFooter As Range

Set rgeFooter =
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range

With rgeFooter
.Collapse wdCollapseStart
Set myField = ActiveDocument.Fields.Add(Range:=rgeFooter, _
Type:=wdFieldUserName)
End With

End Sub