Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to overwrite an existing header or footer in Word Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
24-Feb-04
Category
OLE
Language
Delphi 3.x
Views
140
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Can anyone provide an example of how to set the header and footer for an entire 
Word document, replacing any existing header or footer?

Answer:

This example assumes one section and no odd/ even or different first page headers. 
Doing the Range.Select selects all text that may have been previously there, so you 
can use this to write the first time or to change it later. Note that if you want 
different headers on different pages (besides odd/ even) you will need to use 
sections.

1   { ... }
2   Word.ActiveDocument.Sections.Item(1).Headers.Item(1).Range.Select;
3   Word.Selection.ParagraphFormat.TabStops.ClearAll;
4   {Set tab types to be used in header}
5   OleVar := wdAlignTabLeft;
6   OleVar2 := wdTabLeaderSpaces;
7   {Set tabs}
8   Word.Selection.ParagraphFormat.TabStops.Add(190, OleVar, OleVar2);
9   Word.Selection.ParagraphFormat.TabStops.Add(365, OleVar, OleVar2);
10  {Now tab over and write the header field}
11  Word.Selection.TypeText(WideString(#9)); {to centered text}
12  Word.Selection.TypeText(WideString('This Is The Header'));
13  Word.Selection.TypeText(WideString(#9));
14  Word.Selection.TypeText(WideString('Blah Blah'));
15  {Now do the footer}
16  Word.ActiveDocument.Sections.Item(1).Footers.Item(1).Range.Select;
17  Word.Selection.ParagraphFormat.TabStops.ClearAll;
18  {Set tab types to be used in header}
19  OleVar := wdAlignTabLeft;
20  OleVar2 := wdTabLeaderSpaces;
21  {Set tabs}
22  Word.Selection.ParagraphFormat.TabStops.Add(190, OleVar, OleVar2);
23  Word.Selection.TypeText(WideString(#9));
24  Word.Selection.TypeText(WideString('This Is The Footer'));
25  { ... }


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC