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
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