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 / August 2007

Tip: Looking for answers? Try searching our database.

Inserting table in footer and formatting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
faberk - 07 Aug 2007 00:02 GMT
I need to cycle through the .doc files in a folder and replace the footers in
each document.  I am having difficulty inserting a table in a footer, merging
cells in the table, adding text, formatting that text (alignment within the
table cells, bolding etc)  I attempted to use the recorder to provide me some
insight on how to do it, but it will not allow me to move the cursor to cells
in the table, etc.  I need to insert a 2 column, 2 row table, merge the cells
in the top row, insert text in the row in additiona to centering it, insert
path and file name in the lower left cell and the date and time and page # in
the lower right cell.  Any help, direction or info sources would help at this
point.

Thank you in advance.
John Smith - 07 Aug 2007 01:42 GMT
If it's the same table for every document, a simpler solution is to set the
table up once, and define it as an autotext entry. Then your code simply
inserts the entry --

   NormalTemplate.AutoTextEntries("FooterTable").Insert
Where:=ActiveDocument.StoryRanges(wdPrimaryFooterStory), RichText:=True

>I need to cycle through the .doc files in a folder and replace the footers
>in
[quoted text clipped - 17 lines]
>
> Thank you in advance.
Doug Robbins - Word MVP - 07 Aug 2007 03:28 GMT
Dim myrange As Range, mytable As Table
Set myrange =
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
Set mytable = ActiveDocument.Tables.Add(myrange, 2, 2)
With mytable
   .Rows(1).Cells.Merge
   .Cell(1, 1).Range.Text = "Add this text"
   .Cell(1, 1).Range.Paragraphs(1).Alignment = wdAlignParagraphCenter
End With
Set myrange = mytable.Cell(2, 1).Range
myrange.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldEmpty, Text:= _
       "FILENAME  \p "
Set myrange = mytable.Cell(2, 2).Range
myrange.End = myrange.End - 1
myrange.Collapse wdCollapseEnd
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldEmpty, Text:= _
       "DATE  \@ ""d MMMM yyyy h:mm am/pm"" "
Set myrange = mytable.Cell(2, 2).Range
myrange.End = myrange.End - 1
myrange.Collapse wdCollapseEnd
myrange.InsertBefore " - Page "
myrange.Collapse wdCollapseEnd
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldEmpty, Text:= _
       "PAGE"
myrange.Paragraphs.Alignment = wdAlignParagraphRight

Incorporate the above into a modification of the macro in the article "Find
& ReplaceAll on a batch of documents in the same folder" at:

http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

If you want to do it to multiple files.

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

>I need to cycle through the .doc files in a folder and replace the footers
>in
[quoted text clipped - 17 lines]
>
> Thank you in advance.
 
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.