Inserting fields and text to the footer without changing the current view

B

bts

Hello
I would like to put some info from vba code to the footer
here you are my code colleted it from some article
But my problem is that, if the view was "print layout" the macr
wil
it turn to the normal view, and switch on the footer panel
In any other case it will only switch the footer panel o
I would like to insert the info to the all footer without changing the screen
Any help would be appreciate

Public Sub AddFooterAndPrint(

Application.ScreenUpdating = Fals

ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Range.Selec
With Selectio
.Paragraphs(1).Alignment = wdAlignParagraphCente
.TypeText Text:="page &quot
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="Pag
"
PreserveFormatting:=Tru
.TypeText Text:=" per &quot
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="NUMPAGE
", PreserveFormatting:=Tru
.TypeText Text:=" " & LoggedInUserName() & " &quot
End Wit
Application.ScreenUpdating = Tru
End Sub
 
D

Doug Robbins - Word MVP

Use code such as the following:

Dim frange As Range
With
ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary)
Set frange = .Range
With frange
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Text = "Page "
.Collapse wdCollapseEnd
ActiveDocument.Fields.Add frange, wdFieldEmpty, "Page"
End With
Set frange = .Range
With frange
.Collapse wdCollapseEnd
.Text = " of "
.Collapse wdCollapseEnd
ActiveDocument.Fields.Add frange, wdFieldEmpty, "Numpages"
End With
End With
 

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