Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Text inside footer in all sections

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sammy - 06 Nov 2007 02:09 GMT
Hello,

I need to have the filename (on every page) and the page number (on every
page except the first) in the footer, in every section of my document.  I
scrub all footers first and I can get that to work.  So far I have:

Dim i As Integer
For i = 1 To ActiveDocument.Sections.Count
   With ActiveDocument.Sections(i)
       .Footers(wdHeaderFooterFirstPage).Range.Delete
       .Footers(wdHeaderFooterFirstPage).Range.Fields.Add
_Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
       "FILENAME  \* Lower ", PreserveFormatting:=True
       
      .Footers(wdHeaderFooterPrimary).Range.Delete
      .Footers(wdHeaderFooterFirstPage).Range.Fields.Add _  
      Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
       "FILENAME  \* Lower ", PreserveFormatting:=True

Selection.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _
       wdAlignPageNumberCenter, FirstPage:=False
   

End With
Next i

IF YOU THINK THIS DOESN'T WORK YOU ARE CORRECT.  IN HELP, THEY ALWAYS GIVE
EXAMPLES USING ONLY A CERTAIN MEMBER OF A COLLECTION SO I COULDN'T FIGURE OUT
HOW TO PUT PAGE NUMBERING IN ALL SECTIONS.  

CAN YOU HELP?  THANKS A LOT
Stefan Blom - 06 Nov 2007 11:13 GMT
The easiest solution would seem to set up a template for this. But if you
want to do it in VBA, the following variation on your code works:

Sub test()
Dim i As Integer
For i = 1 To ActiveDocument.Sections.Count
   With ActiveDocument.Sections(i)
       .Footers(wdHeaderFooterFirstPage).Range.Delete
       ActiveDocument.Fields.Add _
       Range:=.Footers(wdHeaderFooterFirstPage).Range, _
       Type:=wdFieldEmpty, Text:= _
       "FILENAME  \* Lower ", PreserveFormatting:=True

      .Footers(wdHeaderFooterPrimary).Range.Delete
      ActiveDocument.Fields.Add _
      Range:=.Footers(wdHeaderFooterFirstPage).Range, _
      Type:=wdFieldEmpty, Text:= _
      "FILENAME  \* Lower ", PreserveFormatting:=True

      .Footers(wdHeaderFooterPrimary).PageNumbers.Add _
      PageNumberAlignment:=wdAlignPageNumberCenter, FirstPage:=False

End With
Next i
End Sub

Note that when you add a field, you can use any Fields collection (I used
ActiveDocument.Fields just to make the line a bit shorter), but the Range
parameter of the Add method must carefully reference the Range object to
which you are adding the field. (In particular, you cannot use
Selection.Range.)

Signature

Stefan Blom
Microsoft Word MVP

> Hello,
>
[quoted text clipped - 27 lines]
>
> CAN YOU HELP?  THANKS A LOT
Sammy - 06 Nov 2007 21:58 GMT
Thanks for your help!  Okay, I tried it, but it's omitting the filename from
all pages in the section except for the 1st page.  In your code it looks like
the filename should be appearing on every page, but it's not.  Thanks

> The easiest solution would seem to set up a template for this. But if you
> want to do it in VBA, the following variation on your code works:
[quoted text clipped - 59 lines]
> >
> > CAN YOU HELP?  THANKS A LOT
Stefan Blom - 07 Nov 2007 10:47 GMT
Sorry, it seems as if I didn't read your initial post carefully enough... My
suggestion only inserts the file name in the first page header. The good news
is that Doug has given you what you asked for.  :-)

Signature

Stefan Blom
Microsoft Word MVP

> Thanks for your help!  Okay, I tried it, but it's omitting the filename from
> all pages in the section except for the 1st page.  In your code it looks like
[quoted text clipped - 63 lines]
> > >
> > > CAN YOU HELP?  THANKS A LOT
Sammy - 06 Nov 2007 22:10 GMT
One other question if you don't mind, what is the best approach to formatting
the filename field with an 8pt font?  I would select and then format after
the field was inserted.  Is this the best method?  thanks again

> The easiest solution would seem to set up a template for this. But if you
> want to do it in VBA, the following variation on your code works:
[quoted text clipped - 59 lines]
> >
> > CAN YOU HELP?  THANKS A LOT
Doug Robbins - Word MVP - 07 Nov 2007 02:33 GMT
Use this corrected, augmented version of Stefan's code:

Dim i As Integer
For i = 1 To 1 'ActiveDocument.Sections.Count
   With ActiveDocument.Sections(1)
       .Footers(wdHeaderFooterFirstPage).Range.Delete
       ActiveDocument.Fields.Add _
       Range:=.Footers(wdHeaderFooterFirstPage).Range, _
       Type:=wdFieldEmpty, Text:= _
       "FILENAME  \* Lower ", PreserveFormatting:=True
      .Footers(wdHeaderFooterFirstPage).Range.Font.Size = 8
      .Footers(wdHeaderFooterPrimary).Range.Delete
      ActiveDocument.Fields.Add _
      Range:=.Footers(wdHeaderFooterPrimary).Range, _
      Type:=wdFieldEmpty, Text:= _
      "FILENAME  \* Lower ", PreserveFormatting:=True
      .Footers(wdHeaderFooterPrimary).PageNumbers.Add _
      PageNumberAlignment:=wdAlignPageNumberCenter, firstPage:=False
      .Footers(wdHeaderFooterPrimary).Range.Paragraphs(2).Range.Font.Size =
8
End With
Next i

Signature

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

> One other question if you don't mind, what is the best approach to
> formatting
[quoted text clipped - 69 lines]
>> >
>> > CAN YOU HELP?  THANKS A LOT
Sammy - 08 Nov 2007 16:33 GMT
THANK YOU DOUG AND STEFAN FOR YOUR HELP!!!  WORKS GREAT!

> Use this corrected, augmented version of Stefan's code:
>
[quoted text clipped - 92 lines]
> >> >
> >> > CAN YOU HELP?  THANKS A LOT
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.