Inserting table in footer and formatting

F

faberk

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

John Smith

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
 
D

Doug Robbins - Word MVP

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.

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