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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add picture in word documents 1

Status
Not open for further replies.

gcaramia

Programmer
Oct 30, 2003
185
0
0
IT
With Delphi 7 Pro
I need to add a picture (signature) at the bottom of word documents (office 2003/2007). Documents may have one or more pages each.
I'have tried with ole:

Code:
uses 
   comobj;

procedure TForm1.Button1Click(Sender: TObject);
var wdgotolast,wdgotopage,wdgotoabsolute : olevariant;
begin
   Word := CreateOLEObject('Word.Application');

   Word.Visible := true;

   Word.Documents.Open(GetCurrentDir+'\word.doc');

   word.Selection.GoTo(wdGotoPage,wdGoToLast,wdgotoabsolute,EmptyParam);
   word.selection.inlineshapes.addpicture('c:\firma.jpg');

   .....
   word.free;
end;

but the picture is inserted at the beginning of the document not at the end.

I tried also with bookmarks but theese are not recognised.

I'have tried with wdGotoLine/wdGotoLast but in this case the picture is inserted at the end of the first page.

Somebody can help with this code or other one ?
Any components free/shareware/commercial ?

Thanks
Giovanni Caramia
 
DjangMan
No. i didn't.
I can try this solution.
But how can i run the macro from inside Delphi ?
As parameter in ShellExecute ?

Thanks
Giovanni
 
Record the macro so you can see the steps that are required. Then convert those steps to Delphi and run the automation as normal. I would guess that you're missing a line or two of code that the macro will reveal.
 
Thanks DjangMan !!!
Solution:

Code:
uses 
   comobj;

procedure TForm1.Button1Click(Sender: TObject);
var wdgotolast,wdgotopage,wdgotoabsolute : olevariant;
begin
   Word := CreateOLEObject('Word.Application');

   Word.Visible := true;

   Word.Documents.Open(GetCurrentDir+'\word.doc');

   [COLOR=red]word.Selection.EndKey(unit :=wdStory)[/color] ; 

   word.selection.inlineshapes.addpicture('c:\firma.jpg');

   .....
   word.free;
end;
 
Sorry i forgot a library:

Code:
uses
   comobj,word2000;

procedure TForm1.Button1Click(Sender: TObject);
var wdgotolast,wdgotopage,wdgotoabsolute : olevariant;
begin
   Word := CreateOLEObject('Word.Application');

   Word.Visible := true;

   Word.Documents.Open(GetCurrentDir+'\word.doc');

   word.Selection.EndKey(unit :=wdStory) ;

   word.selection.inlineshapes.addpicture('c:\firma.jpg');

   .....
   word := unassigned;
end;

Giovanni Caramia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top