Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could I insert a header into a Word Document in Delphi ?

Status
Not open for further replies.

Bogdan81

Programmer
Oct 2, 2002
11
RO
I understand how to create a new Word Document, how to write in it, but i don't know how to insert a header in the document ?
 
I'd guess it is possible, but without knowing how you are creating your Word document I couldn't say how. Robertio
Alias: Robbie Calder
Software Developer
urc@walkermartyn.co.uk
 
Ok Robertio, this is how i do it :

var
WordApplication, WordDocument: Variant;
AddToRecent:Boolean;
begin
WordApplication := CreateOleObject('Word.Application');
WordDocument := WordApplication.Documents.Add;
WordApplication.Selection.TypeText('Hello world');
AddToRecent := False;
WordDocument.SaveAs(FileName := 'C:\Doc.Doc', AddToRecent);
WordApplication.Quit(False);

Hope now you can help me !
 
Robertio
but i found that using OLE is slower than using DDE, so I will use this code :

WordDocument1: TWordDocument;
WordApplication1: TWordApplication;

var
NewTemplate, Visible, ItemIndex : OleVariant;
begin
try
WordApplication1.Connect;
except
MessageDlg('Bla bla bla', mtError, [mbOk], 0);
Abort;
end;
WordApplication1.Visible := True;
NewTemplate := False;
Visible := true;
WordApplication1.Documents.Add(EmptyParam, NewTemplate, EmptyParam, Visible);

now could you help me ?
 
This would be the VBA code to insert a header, but you should look at the following article on Word/Excel from Delphi too because the syntax will be slightly different.

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "Header text"


Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top