sorry :-)
var
W : Variant
Main Topics
Browse All TopicsHow do I Import a Bitmap (image) into a Word-2000 Document programatically from Delphi 7?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hello
Here's a quick sample
uses
ComObj;
procedure TForm1.Button1Click(Sender
var
V : Variant;
Doc : Variant;
begin
V := CreateOleObject('Word.Appl
V.Visible := True;
V.Documents.Add(EmptyParam
V.ActiveDocument.Shapes.Ad
EmptyParam, EmptyParam, EmptyParam);
end;
Regards,
Mohammed
Thank you all for your timely and helpful responses!
I have decided to go with Alisher N's "InlineShapes.AddPicture()
The VBA help from Word is a chore to go through - but an excellent suggestion, thanks Robert!
Thank you MNASMAN. Your suggestion successfully imports the image, but, it uniformly places the image at the top of the file - and then it would have to be moved around via it's Anchor (A process that I'd like to avoid if at all possible. :))
My successful code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Word2000, OleServer, ComCtrls, StdCtrls, Buttons, clipbrd, Qclipbrd,
IWControl, IWExtCtrls, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
btnStart: TBitBtn;
StatusBar1: TStatusBar;
ProgBar: TProgressBar;
WApp: TWordApplication;
Doc1: TWordDocument;
btnReplace: TBitBtn;
ProgBar2: TProgressBar;
Function GetWordDocStrReplacements(
Procedure GetDoc(Sender: TObject; sFile : OleVariant);
Procedure ReleaseActiveDoc(Sender : TObject);
procedure btnStartClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnReplaceClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
sTemplateName, sFilename, varFalse, varTrue : OleVariant;
sTag1, sTag2, sTag3, sTag4, sTag5: String;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.GetDoc(Sender: TObject; sFile: OleVariant);
begin
WApp.Connect;
Doc1.ConnectTo(WApp.Docume
end;
procedure TForm1.ReleaseActiveDoc(Se
begin
Doc1.Disconnect;
WApp.ActiveDocument.Close(
WApp.Quit(varFalse);
end;
procedure TForm1.btnStartClick(Sende
begin
GetDoc(Sender, sTemplateName);
Doc1.SaveAs(sFilename);
ReleaseActiveDoc(Sender);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
varTrue := True;
varFalse := False;
sTemplateName := 'D:\Work\Delphi7\wordplay\
sFilename := 'D:\Work\Delphi7\wordplay\
WApp.Visible := False;
sTag1 := '<month></month>';
sTag2 := '<day></day>';
sTag3 := '<year></year>';
sTag4 := '<picture1></picture1>';
sTag5 := '<picture2></picture2>';
end;
function TForm1.GetWordDocStrReplac
ASearchFor, AReplacement: String): Integer;
var
I : Integer;
Txt: String;
iReplacements, iStart: Integer;
Sentence: Range;
PictureRange : OleVariant;
Begin
iReplacements := 0;
try
ProgBar.Max := ADocument.Range.Sentences.
ProgBar.Min := 1;
ProgBar.Position := 1;
ProgBar.StepBy(1);
For I := 1 To ADocument.Range.Sentences.
Begin
Form1.Caption := 'seeking tags';
If I > ADocument.Range.Sentences.
Sentence := ADocument.Range.Sentences.
Sentence.Select;
ProgBar.StepIt;
iStart := pos('<picture1></picture1>
If iStart > 0 Then
Begin
Txt := 'D:\Work\Delphi7\wordplay\
Form1.Caption := ExtractFileName(Txt);
PictureRange := Sentence;
WApp.Selection.TypeParagra
WApp.Selection.InlineShape
WApp.Selection.TypeParagra
Sentence.Text := '';;
End
else
Begin
iStart := pos(ASearchFor, Sentence.Text); // Text exists at all?
If iStart > 0 Then
Begin
Form1.Caption := 'replacing tags';
Txt := StringReplace(Sentence.Tex
Sentence.Text := Txt;
iReplacements := iReplacements + 1;
End;
End;
End;
finally
Result := iReplacements;
end;
End;
procedure TForm1.btnReplaceClick(Sen
var
I : Integer;
mm, dd, yy: Word;
begin
Form1.Caption := 'Loading doc';
DecodeDate(Now, yy, mm, dd);
GetDoc(Sender, sFilename);
Form1.Caption := 'replacing tags';
Application.ProcessMessage
ProgBar2.Min := 1;
ProgBar2.Max := 4;
ProgBar2.StepBy(1);
ProgBar2.Position := 0;
I := 0;
try
ProgBar2.StepIt;
I := GetWordDocStrReplacements(
ProgBar2.StepIt;
I := I + GetWordDocStrReplacements(
ProgBar2.StepIt;
I := I + GetWordDocStrReplacements(
finally
Form1.Caption := IntToStr(I) + ' replacements made.';
WApp.Visible := True;
Doc1.Repaginate;
Doc1.Save; // User intervention now required, show the form...
end;
end;
procedure TForm1.FormCloseQuery(Send
begin
ReleaseActiveDoc(Sender);
end;
end.
Business Accounts
Answer for Membership
by: Alisher_NPosted on 2004-01-17 at 22:57:31ID: 10139548
W := CreateOleObject('Word.Appl
W.Visible := True;
W.Documents.Add;
W.ActiveDocument.SaveAs('T
W.Selection.TypeText('Here
W.Selection.TypeParagraph;
//---- insert picture: name, link to file, save with document
W.Selection.InlineShapes.A
W.Selection.TypeParagraph;
W.Quit;
// see also MS Word OLE reference
good luck