Help adding footer info on all pages

J

Jennie

I'm new to VBA and am needing to create a macro that displays a dialog
box for the user to enter 3 lines of text. This text should then be
populated in the footer area of every page of the current document
(which will be a template with footers added). I also need to add page
numbers but place them outside footer cell and on the 3rd line down.
Here's what I have got so far .....
It works somewhat but will not put page number on 1st page.
I didn't know how to code to put the page number where they wanted it
(outside footer cell and on 3rd line), so I recorded a macro for this
piece.
I've tried bookmarks and fields also, and just cannot get the right
combination.
Seems like this should be easier than this!
Please help.

Private Sub cmdOK_Click()
Dim secTemp As Section
Dim strClient As String
Dim strProject As String
Dim strDueDate As String

'Get the input and place in variables
strClient = txtClientName.Text
strProject = txtProjectTitle.Text
strDueDate = txtDueDate.Text

Set secTemp = ActiveDocument.Sections(1)

If secTemp.Footers(wdHeaderFooterFirstPage).Exists = True Then
secTemp.Footers(wdHeaderFooterFirstPage).Range.Text = strProject _
+ vbCrLf + strClient + vbCrLf + strDueDate
Call PageNo
End If

If secTemp.Footers(wdHeaderFooterPrimary).Exists = True Then
secTemp.Footers(wdHeaderFooterPrimary).Range.Text = _
strProject + vbCrLf + strClient + vbCrLf + strDueDate
Call PageNo
End If

Unload Me

End Sub


Sub PageNo()
' 'PageNo Macro'
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
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=8
Selection.TypeText Text:=vbTab
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
 
D

Doug Robbins - Word MVP

I would set up the template with { DOCVARIABLE varname } fields in the
header and footers where you want them and also the page number where it is
wanted and have your code set the values of the document variables and
update the fields in the range of the respective headers and footers.

Much easier than using code to create headers and footers.

Private Sub cmdOK_Click()
Dim i As Long
With ActiveDocument
.Variables("strClient").Value = txtClientName.Text
.Variables("strProject").Value = txtProjectTitle.Text
.Variables("strDueDate").Value = txtDueDate.Text
For i = 1 To .Sections.Count
.Sections(i).Footers(wdHeaderFooterFirstPage).Range.Fields.Update
.Sections(i).Footers(wdHeaderFooterPrimary).Range.Fields.Update
Next i
End With
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top