roosiedb
asked on
Printing invoices in MS Word: from Paradox to Word...
HELP ME PLEASE...
In my invoice-application, I want to send data fromout a Paradox-table to Word. I really don't know how to do the following:
- I want to startup MS Word from my application,
- Open a specific template,
- Fill the fields with the data I selected en save the file as a Word-document.
Because I am a real beginner, I would like to ask you to give me an example which I can follow step by step...
Thank you very much for helping me...!!!
Jan van Barchum.
In my invoice-application, I want to send data fromout a Paradox-table to Word. I really don't know how to do the following:
- I want to startup MS Word from my application,
- Open a specific template,
- Fill the fields with the data I selected en save the file as a Word-document.
Because I am a real beginner, I would like to ask you to give me an example which I can follow step by step...
Thank you very much for helping me...!!!
Jan van Barchum.
Have a look at Dynamic Data Exchange (DDE) and OLE Automation in the Delphi help and MSWord help, that should give you some basic idea.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hello???
ASKER
Sorry, I didn't read your answer yet, I will try to implement your solution this weekend. You'll hear from me soon, OK?
Jan.
Jan.
ok :-)
Hi Roosiedb,
did that help you?
Rob ;-)
did that help you?
Rob ;-)
ASKER
I'm very sorry again, I still did not try out your solution. I really will try it this weekend. Within 4 days I will reply... Hope you don't mind...
The only thing I still can not see in your code is the way to handle an x-number of invoice-details... It isn't known how much orderdetails there are for one invoice...
Greetz...
The only thing I still can not see in your code is the way to handle an x-number of invoice-details... It isn't known how much orderdetails there are for one invoice...
Greetz...
ASKER
Because I did not tell you that I want to use this solution to export data for invoicing, I will only judge the first part of my problem, but it would be very nice when you can answer this accompanying problem too...
Greetz again...
Greetz again...
1. connect to word
// to handle multiple invoices:
Query1.Open; // to get your database records
for lp := 1 to NumberOfInvoices do
begin
//open template
WordApp.Documents.Open('c: template.d oc');
// run merge
MergeFindReplace1Click(Sen der); //use query1.fields to replace
// save the docuemnt as your invoice number
WordApp.ActiveDocument.Sav eAs(FullFi leNameInvo iceNumber) ;
Query1.Next;
end;
Hint: its a good idea to make sure template.doc is readonly
as you don't want to accidentally delete it
Rob ;-)
// to handle multiple invoices:
Query1.Open; // to get your database records
for lp := 1 to NumberOfInvoices do
begin
//open template
WordApp.Documents.Open('c:
// run merge
MergeFindReplace1Click(Sen
// save the docuemnt as your invoice number
WordApp.ActiveDocument.Sav
Query1.Next;
end;
Hint: its a good idea to make sure template.doc is readonly
as you don't want to accidentally delete it
Rob ;-)
ASKER
It almost works !!
Only when my Word-application was already there, the merge will work OK. But when I did not startup Word before I startup my Delphi-program, my application is not able to startup MS Word for me... Too bad!
I think something went wrong with these lines:
// connect or open word
try
WordApp := GetActiveOleObject('Word.A pplication ');
except on exception do
WordApp := CreateOleObject('Word.Appl ication');
end;
When I run these lines, I get the following error-message: "Project Project1.exe raised exception class EOleSysError with message 'Bewerking is niet beschikbaar'. Process stopped. Use Step or Run to continue.".
NB. The message was in Dutch, it means something like "action not available".
So: please don't give up and continue with your help...
---
The other question (I will increase my points to 300 when this all works perfect!) was not completely understood I guess...
I didn't mean to use more than one invoice, but I want to fill more than one invoice-row. And every invoice can have a random number of rows. (For example: the first invoice does have 2 rows: the customer bought a book and a pencil; the second invoice does have 1 row: the customer bought ten magazines). I hope these examples will clear up the question.
Thank you very much for helping me !!!!
Jan van Barchum.
Only when my Word-application was already there, the merge will work OK. But when I did not startup Word before I startup my Delphi-program, my application is not able to startup MS Word for me... Too bad!
I think something went wrong with these lines:
// connect or open word
try
WordApp := GetActiveOleObject('Word.A
except on exception do
WordApp := CreateOleObject('Word.Appl
end;
When I run these lines, I get the following error-message: "Project Project1.exe raised exception class EOleSysError with message 'Bewerking is niet beschikbaar'. Process stopped. Use Step or Run to continue.".
NB. The message was in Dutch, it means something like "action not available".
So: please don't give up and continue with your help...
---
The other question (I will increase my points to 300 when this all works perfect!) was not completely understood I guess...
I didn't mean to use more than one invoice, but I want to fill more than one invoice-row. And every invoice can have a random number of rows. (For example: the first invoice does have 2 rows: the customer bought a book and a pencil; the second invoice does have 1 row: the customer bought ten magazines). I hope these examples will clear up the question.
Thank you very much for helping me !!!!
Jan van Barchum.
Hmm for thaat sort of thing you need to write out all the contents of the word document from scratch.. ie do not use find replace.
Here is a wrapper object I have written to help me generate word documents:
I have also included some sample so you can see how to use it
Rob;-)
unit MainDocTemplateFunctions;
{ This module or unit does not describe a form, therefore it is a nonvisual piece
of code. It contains the declaration and implementation of a new object called
MyWordAppObject. I use this object to wrap certain ole functions for word97.
These functions correspond to all the functions exported by the DocumentsTemplate
program. - very simple
Note: There function called write database, which simply writes the variable stored in
the fdatabasevalue variable to the open word document which is contained in the
FWordApp variant variable.
}
interface
uses classes,sysutils,Forms;
type MyWordAppObject = class(TComponent)
private
FWordApp : Variant;
FDatabaseValue : String;
public
Property WordApp : Variant read FWordApp Write FWordApp;
property DatabaseValue : String read FDatabaseValue write FDatabaseValue;
Constructor Create(AnOwner : TComponent); override;
Destructor Destroy; override;
function InsertDate : Boolean;
function InsertDateTime : Boolean;
function InsertTime : Boolean;
function OpenHeader : Boolean;
function CloseHeader : Boolean;
function Tab : Boolean;
function Enter : Boolean;
function SetAlignmentLeft : Boolean;
function SetAlignmentCenter : Boolean;
function SetAlignmentRight : Boolean;
function ToggleUnderLine : Boolean;
function ToggleBold : Boolean;
function ToggleItalic : Boolean;
function OpenFooter : Boolean;
function CloseFooter : Boolean;
function NewParagraph : Boolean;
function WriteString(S : String) : Boolean; virtual;
function SetHeadingStyle(S:String): Boolean; {'Heading 1','Heading 2','Heading 3','Normal'}
function InsertImage(FileName:Strin g): Boolean;
function SetFontSize(I : Integer): Boolean;
function SetColor(I : Integer): Boolean;
{1 = black 2 = blue 3 = aqua 4 = lime 5 = fuschia 6 = red 7 = yellow 8 = white 9 = navy 10 = teal 16 = silver}
function SetFont(S : String): Boolean;
{'Arial','Times New Roman','Arial Narrow','Arial Black','Courier','Courier New','Impact','Letter Gothic','Marigold','Symbol '}
procedure ExecuteFunction(FunctionNa me : String);
function PullStringParameter(Functi onName : String) : String;
function PullIntegerParameter(Funct ionName : String) : String;
// functionRunFunction
end;
//exports MyWordAppObject;
(*
exports Proc1, Proc2;
Then you can do this:
procedure runStrProc(procStrVar: string);
var proc : procedure;
begin
proc:=GetProcAddress(hInst ance,procS trVar);
if @proc<>nil then proc;
end;
procedure TForm1.Button7Click(Sender : TObject);
begin
showmessage('hello');
ThisApp := MyWordAppObject.Create(For m1);
showmessage('hello');
ThisApp.WordApp := WordApp;
ThisApp.WriteString('hello world');
ThisSyntaxApp := MyWordAppObjectSyntaxCheck .Create(Th isApp);
ThisSyntaxApp.WriteString( '......... ...Hello') ;
end;
procedure TForm1.Button10Click(Sende r: TObject);
begin
ThisSyntaxApp.Destroy;
ThisApp.Destroy;
end;
*)
implementation
{ MyWordAppObject }
function MyWordAppObject.CloseFoote r: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.View.Typ e := 1; //normalview
result := True ;
end;
function MyWordAppObject.CloseHeade r: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.View.Typ e := 1; // normalview
result := True ;
end;
constructor MyWordAppObject.Create(AnO wner : TComponent);
begin
inherited Create(AnOwner);
FWordApp := 0;
end;
destructor MyWordAppObject.Destroy;
begin
inherited Destroy;
end;
function MyWordAppObject.Enter: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.TypeText (#10);
result := True ;
end;
procedure MyWordAppObject.ExecuteFun ction(Func tionName: String);
var
OpenBracketIndex : Integer;
JustTheName : String;
begin
OpenBracketIndex := Pos('(',FunctionName);
if OpenBracketIndex <> 0 then
JustTheName := Copy(FunctionName,1,OpenBr acketIndex -1)
else
JustTheName := Copy(FunctionName,1,Length (FunctionN ame)-1);
if uppercase(JustTheName) = 'INSERTDATE' then InsertDate;
if uppercase(JustTheName) = 'INSERTDATETIME' then InsertDateTime;
if uppercase(JustTheName) = 'INSERTTIME' then InsertTime;
if uppercase(JustTheName) = 'WRITEDATABASE' then
begin
WriteString(FDatabaseValue );
end;
if uppercase(JustTheName) = 'OPENHEADER' then OpenHeader;
if uppercase(JustTheName) = 'CLOSEHEADER' then CloseHeader;
if uppercase(JustTheName) = 'TAB' then Tab;
if uppercase(JustTheName) = 'ENTER' then Enter;
if uppercase(JustTheName) = 'SETALIGNMENTLEFT' then SetalignmentLeft;
if uppercase(JustTheName) = 'SETALIGNMENTCENTER' then SetAlignmentCenter;
if uppercase(JustTheName) = 'SETALIGNMENTRIGHT' then SetAlignmentRight;
if uppercase(JustTheName) = 'TOGGLEUNDERLINE' then ToggleUnderLine;
if uppercase(JustTheName) = 'TOGGLEBOLD' then Togglebold;
if uppercase(JustTheName) = 'TOGGLEITALIC' then ToggleItalic;
if uppercase(JustTheName) = 'OPENFOOTER' then OpenFooter;
if uppercase(JustTheName) = 'CLOSEFOOTER' then CloseFooter;
if uppercase(JustTheName) = 'NEWPARAGRAPH' then NewParagraph;
if uppercase(JustTheName) = 'WRITESTRING' then WriteString(PullStringPara meter(Func tionName)) ;
if uppercase(JustTheName) = 'SETHEADINGSTYLE' then SetHeadingStyle(PullString Parameter( FunctionNa me));
if uppercase(JustTheName) = 'INSERTIMAGE' then InsertImage(PullStringPara meter(Func tionName)) ;
if uppercase(JustTheName) = 'SETCOLOR' then SetColor(StrToInt(PullInte gerParamet er(Functio nName)));
if uppercase(JustTheName) = 'SETFONT' then SetFont(PullStringParamete r(Function Name));
if uppercase(JustTheName) = 'SETFONTSIZE' then SetFontSize(StrToInt(PullI ntegerPara meter(Func tionName)) );
end;
function MyWordAppObject.InsertDate : Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.TypeText (FormatDat eTime('mmm m dd yyyy',Date));
result := True ;
end;
function MyWordAppObject.InsertDate Time: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.TypeText (FormatDat eTime('mmm dd yyyy hh:nn:ss',Now));
result := True ;
end;
function MyWordAppObject.InsertImag e(FileName : String): Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.TypePara graph; //enter
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.InlineSh apes.AddPi cture(File Name,False ,True);
result := True ;
end;
function MyWordAppObject.InsertTime : Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.TypeText (TimeToStr (Time));
result := True ;
end;
function MyWordAppObject.NewParagra ph: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.TypePara graph;
result := True ;
end;
function MyWordAppObject.OpenFooter : Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.View.Typ e := 2; //not normalview
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.View.See kView := 10; // footer
result := True ;
end;
function MyWordAppObject.OpenHeader : Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.View.Typ e := 2; //not normalview
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.View.See kView := 9; //header
result := True ;
end;
function MyWordAppObject.PullIntege rParameter (
FunctionName: String): String;
var
Index : Integer;
begin
Index := pos('(',FunctionName);
Delete(Functionname,1,Inde x);
Index := pos(')',FunctionName);
result := Copy(FunctionName,1,Index- 1);
end;
function MyWordAppObject.PullString Parameter( FunctionNa me: String): String;
var
Index : Integer;
TempString : String;
begin
Index := pos('"',FunctionName);
Delete(Functionname,1,Inde x);
Index := pos('"',FunctionName);
TempString := Copy(FunctionName,1,Index- 1);
// replace char177 with colon
Index := pos(#177,TempString);
while Index <> 0 do
begin
TempString[Index] := ':';
Index := pos(#177,TempString)
end;
Result := TempString;
end;
function MyWordAppObject.SetAlignme ntCenter: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.Paragrap hFormat.Al ignment := 1;
result := True ;
end;
function MyWordAppObject.SetAlignme ntLeft: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.Paragrap hFormat.Al ignment := 0;
result := True ;
end;
function MyWordAppObject.SetAlignme ntRight: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.Paragrap hFormat.Al ignment := 2;
result := True ;
end;
function MyWordAppObject.SetColor(I : Integer): Boolean;
{1 = black 2 = blue 3 = aqua 4 = lime 5 = fuschia 6 = red 7 = yellow 8 = white 9 = navy 10 = teal 16 = silver}
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.Font.Col orIndex := I;
result := True ;
end;
function MyWordAppObject.SetFont(S: String): Boolean;
{'Arial','Times New Roman','Arial Narrow','Arial Black','Courier','Courier New','Impact','Letter Gothic','Marigold','Symbol '}
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.Font.Nam e := S;
result := True ;
end;
function MyWordAppObject.SetFontSiz e(I: Integer): Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.Font.Siz e := I;
result := True ;
end;
function MyWordAppObject.SetHeading Style(S: String): Boolean;
{'Heading 1','Heading 2','Heading 3','Normal'}
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.Range.St yle := S;
result := True ;
end;
function MyWordAppObject.Tab: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.TypeText (#9);
result := True ;
end;
function MyWordAppObject.ToggleBold : Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.font.Bol d := 9999998;
result := True ;
end;
function MyWordAppObject.ToggleItal ic: Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.font.Ita lic := 9999998;
result := True ;
end;
function MyWordAppObject.ToggleUnde rLine: Boolean;
begin
if FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.font.und erline = 0 then
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.font.und erline := 1
else
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.font.und erline := 0;
result := True ;
end;
function MyWordAppObject.WriteStrin g(S: String): Boolean;
begin
FWordApp.ActiveDocument.Ac tiveWindow .ActivePan e.Selectio n.TypeText (S);
result := True ;
end;
end.
// how to use the unit:
uses MaindDocTemplateFunctions
var
WordApp : Variant;
ThisApp : MyWordAppObject;
BEGIN
// connect or open word using the WordApp Variant
try
WordApp := GetActiveOleObject('Word.A pplication ');
except on exception do
WordApp := CreateOleObject('Word.Appl ication');
end;
// Create my wrapper object and assign it to the WordApp variant
ThisApp := MyWordAppObject.Create(For m1);
ThisApp.WordApp := WordApp;
// Now you can run any of the functions exported by my object
with ThisApp do
begin
NewParagraph;
NewParagraph;
NewParagraph;
WriteString(Query1.FieldBy Name('Clie ntName').A sString);
NewParagraph;
WriteString(Query1.FieldBy Name('Clie ntAddress1 ').AsStrin g);
NewParagraph;
InsertDate;
NewParagraph;
NewParagraph;
ToggleBold;
WriteString("Document Ref # ");
WriteString(Query1.FieldBy Name('Even tNumber'). AsString);
ToggleBold;
NewParagraph;
NewParagraph;
WriteString("Dear ");
WriteString((Query1.FieldB yName('Eve ntNumber') .AsString;
NewParagraph;
OpenHeader;
SetAlignmentCenter;
SetColor(6);
WriteString("This is a red coloured centered header");
CloseHeader;
OpenFooter;
WriteString("This is a footer my last example");
CloseFooter;
WriteString("Hello world");
// add multiple database rows into document
Query2.First;
for Lp := 1 to Query2.RecordCount-1 do
begin
WriteString(Query2.FieldBy Name('Invo iceRow').A sString);
NewParagraph;
Query2.Next;
end;
NewParagraph;
NewParagraph;
SetAlignmentRight;
InsertDate;
NewParagraph;
NewParagraph;
end;
END;
// remember to free the object
ThisApp.Destroy;
Here is a wrapper object I have written to help me generate word documents:
I have also included some sample so you can see how to use it
Rob;-)
unit MainDocTemplateFunctions;
{ This module or unit does not describe a form, therefore it is a nonvisual piece
of code. It contains the declaration and implementation of a new object called
MyWordAppObject. I use this object to wrap certain ole functions for word97.
These functions correspond to all the functions exported by the DocumentsTemplate
program. - very simple
Note: There function called write database, which simply writes the variable stored in
the fdatabasevalue variable to the open word document which is contained in the
FWordApp variant variable.
}
interface
uses classes,sysutils,Forms;
type MyWordAppObject = class(TComponent)
private
FWordApp : Variant;
FDatabaseValue : String;
public
Property WordApp : Variant read FWordApp Write FWordApp;
property DatabaseValue : String read FDatabaseValue write FDatabaseValue;
Constructor Create(AnOwner : TComponent); override;
Destructor Destroy; override;
function InsertDate : Boolean;
function InsertDateTime : Boolean;
function InsertTime : Boolean;
function OpenHeader : Boolean;
function CloseHeader : Boolean;
function Tab : Boolean;
function Enter : Boolean;
function SetAlignmentLeft : Boolean;
function SetAlignmentCenter : Boolean;
function SetAlignmentRight : Boolean;
function ToggleUnderLine : Boolean;
function ToggleBold : Boolean;
function ToggleItalic : Boolean;
function OpenFooter : Boolean;
function CloseFooter : Boolean;
function NewParagraph : Boolean;
function WriteString(S : String) : Boolean; virtual;
function SetHeadingStyle(S:String):
function InsertImage(FileName:Strin
function SetFontSize(I : Integer): Boolean;
function SetColor(I : Integer): Boolean;
{1 = black 2 = blue 3 = aqua 4 = lime 5 = fuschia 6 = red 7 = yellow 8 = white 9 = navy 10 = teal 16 = silver}
function SetFont(S : String): Boolean;
{'Arial','Times New Roman','Arial Narrow','Arial Black','Courier','Courier New','Impact','Letter Gothic','Marigold','Symbol
procedure ExecuteFunction(FunctionNa
function PullStringParameter(Functi
function PullIntegerParameter(Funct
// functionRunFunction
end;
//exports MyWordAppObject;
(*
exports Proc1, Proc2;
Then you can do this:
procedure runStrProc(procStrVar: string);
var proc : procedure;
begin
proc:=GetProcAddress(hInst
if @proc<>nil then proc;
end;
procedure TForm1.Button7Click(Sender
begin
showmessage('hello');
ThisApp := MyWordAppObject.Create(For
showmessage('hello');
ThisApp.WordApp := WordApp;
ThisApp.WriteString('hello
ThisSyntaxApp := MyWordAppObjectSyntaxCheck
ThisSyntaxApp.WriteString(
end;
procedure TForm1.Button10Click(Sende
begin
ThisSyntaxApp.Destroy;
ThisApp.Destroy;
end;
*)
implementation
{ MyWordAppObject }
function MyWordAppObject.CloseFoote
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.CloseHeade
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
constructor MyWordAppObject.Create(AnO
begin
inherited Create(AnOwner);
FWordApp := 0;
end;
destructor MyWordAppObject.Destroy;
begin
inherited Destroy;
end;
function MyWordAppObject.Enter: Boolean;
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
procedure MyWordAppObject.ExecuteFun
var
OpenBracketIndex : Integer;
JustTheName : String;
begin
OpenBracketIndex := Pos('(',FunctionName);
if OpenBracketIndex <> 0 then
JustTheName := Copy(FunctionName,1,OpenBr
else
JustTheName := Copy(FunctionName,1,Length
if uppercase(JustTheName) = 'INSERTDATE' then InsertDate;
if uppercase(JustTheName) = 'INSERTDATETIME' then InsertDateTime;
if uppercase(JustTheName) = 'INSERTTIME' then InsertTime;
if uppercase(JustTheName) = 'WRITEDATABASE' then
begin
WriteString(FDatabaseValue
end;
if uppercase(JustTheName) = 'OPENHEADER' then OpenHeader;
if uppercase(JustTheName) = 'CLOSEHEADER' then CloseHeader;
if uppercase(JustTheName) = 'TAB' then Tab;
if uppercase(JustTheName) = 'ENTER' then Enter;
if uppercase(JustTheName) = 'SETALIGNMENTLEFT' then SetalignmentLeft;
if uppercase(JustTheName) = 'SETALIGNMENTCENTER' then SetAlignmentCenter;
if uppercase(JustTheName) = 'SETALIGNMENTRIGHT' then SetAlignmentRight;
if uppercase(JustTheName) = 'TOGGLEUNDERLINE' then ToggleUnderLine;
if uppercase(JustTheName) = 'TOGGLEBOLD' then Togglebold;
if uppercase(JustTheName) = 'TOGGLEITALIC' then ToggleItalic;
if uppercase(JustTheName) = 'OPENFOOTER' then OpenFooter;
if uppercase(JustTheName) = 'CLOSEFOOTER' then CloseFooter;
if uppercase(JustTheName) = 'NEWPARAGRAPH' then NewParagraph;
if uppercase(JustTheName) = 'WRITESTRING' then WriteString(PullStringPara
if uppercase(JustTheName) = 'SETHEADINGSTYLE' then SetHeadingStyle(PullString
if uppercase(JustTheName) = 'INSERTIMAGE' then InsertImage(PullStringPara
if uppercase(JustTheName) = 'SETCOLOR' then SetColor(StrToInt(PullInte
if uppercase(JustTheName) = 'SETFONT' then SetFont(PullStringParamete
if uppercase(JustTheName) = 'SETFONTSIZE' then SetFontSize(StrToInt(PullI
end;
function MyWordAppObject.InsertDate
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.InsertDate
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.InsertImag
begin
FWordApp.ActiveDocument.Ac
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.InsertTime
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.NewParagra
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.OpenFooter
begin
FWordApp.ActiveDocument.Ac
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.OpenHeader
begin
FWordApp.ActiveDocument.Ac
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.PullIntege
FunctionName: String): String;
var
Index : Integer;
begin
Index := pos('(',FunctionName);
Delete(Functionname,1,Inde
Index := pos(')',FunctionName);
result := Copy(FunctionName,1,Index-
end;
function MyWordAppObject.PullString
var
Index : Integer;
TempString : String;
begin
Index := pos('"',FunctionName);
Delete(Functionname,1,Inde
Index := pos('"',FunctionName);
TempString := Copy(FunctionName,1,Index-
// replace char177 with colon
Index := pos(#177,TempString);
while Index <> 0 do
begin
TempString[Index] := ':';
Index := pos(#177,TempString)
end;
Result := TempString;
end;
function MyWordAppObject.SetAlignme
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.SetAlignme
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.SetAlignme
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.SetColor(I
{1 = black 2 = blue 3 = aqua 4 = lime 5 = fuschia 6 = red 7 = yellow 8 = white 9 = navy 10 = teal 16 = silver}
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.SetFont(S:
{'Arial','Times New Roman','Arial Narrow','Arial Black','Courier','Courier New','Impact','Letter Gothic','Marigold','Symbol
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.SetFontSiz
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.SetHeading
{'Heading 1','Heading 2','Heading 3','Normal'}
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.Tab: Boolean;
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.ToggleBold
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.ToggleItal
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.ToggleUnde
begin
if FWordApp.ActiveDocument.Ac
FWordApp.ActiveDocument.Ac
else
FWordApp.ActiveDocument.Ac
result := True ;
end;
function MyWordAppObject.WriteStrin
begin
FWordApp.ActiveDocument.Ac
result := True ;
end;
end.
// how to use the unit:
uses MaindDocTemplateFunctions
var
WordApp : Variant;
ThisApp : MyWordAppObject;
BEGIN
// connect or open word using the WordApp Variant
try
WordApp := GetActiveOleObject('Word.A
except on exception do
WordApp := CreateOleObject('Word.Appl
end;
// Create my wrapper object and assign it to the WordApp variant
ThisApp := MyWordAppObject.Create(For
ThisApp.WordApp := WordApp;
// Now you can run any of the functions exported by my object
with ThisApp do
begin
NewParagraph;
NewParagraph;
NewParagraph;
WriteString(Query1.FieldBy
NewParagraph;
WriteString(Query1.FieldBy
NewParagraph;
InsertDate;
NewParagraph;
NewParagraph;
ToggleBold;
WriteString("Document Ref # ");
WriteString(Query1.FieldBy
ToggleBold;
NewParagraph;
NewParagraph;
WriteString("Dear ");
WriteString((Query1.FieldB
NewParagraph;
OpenHeader;
SetAlignmentCenter;
SetColor(6);
WriteString("This is a red coloured centered header");
CloseHeader;
OpenFooter;
WriteString("This is a footer my last example");
CloseFooter;
WriteString("Hello world");
// add multiple database rows into document
Query2.First;
for Lp := 1 to Query2.RecordCount-1 do
begin
WriteString(Query2.FieldBy
NewParagraph;
Query2.Next;
end;
NewParagraph;
NewParagraph;
SetAlignmentRight;
InsertDate;
NewParagraph;
NewParagraph;
end;
END;
// remember to free the object
ThisApp.Destroy;
Hi,
I am going on 2-3 months holiday this friday. So please if you have any questions then ask them NOW.
otherwise please raise the points to 300 and grade this question as promissed.
Thanks
Rob ;-)
I am going on 2-3 months holiday this friday. So please if you have any questions then ask them NOW.
otherwise please raise the points to 300 and grade this question as promissed.
Thanks
Rob ;-)
ASKER
Thank you for your help these days and have a nice holiday! 2-3 MONTHS ?!?! WOW...
Greetings,
Jan van Barchum.
Greetings,
Jan van Barchum.
ASKER
Thanks again...
If you don't mind, please tell me also how to print the document immediately after the fields are filled...
Is something like WordApp.ActiveDocument.Pri nt working right???
Greetings,
Jan van Barchum.
If you don't mind, please tell me also how to print the document immediately after the fields are filled...
Is something like WordApp.ActiveDocument.Pri
Greetings,
Jan van Barchum.
Hi this is your print help:
WordApp.ActiveDocument.Pri ntOut(Back ground, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, FileName, ActivePrinterMacGX, ManualDuplexPrint)
expression Required. An expression that returns an Application, Document, or Window object.
Background Optional Variant. True to have the macro continue while Word prints the document.
Append Optional Variant. True to append the specified document to the file name specified by the OutputFileName argument. False to overwrite the contents of OutputFileName.
Range Optional Variant. The page range. Can be one of the following WdPrintOutRange constants: wdPrintAllDocument, wdPrintCurrentPage, wdPrintFromTo, wdPrintRangeOfPages, or wdPrintSelection.
OutputFileName Optional Variant. If PrintToFile is True, this argument specifies the path and file name of the output file. This argument isn't available on the Macintosh unless QuickDraw GX is installed.
From Optional Variant. The starting page number when Range is set to wdPrintFromTo.
To Optional Variant. The ending page number when Range is set to wdPrintFromTo.
Item Optional Variant. The item to be printed. Can be one of the following WdPrintOutItem constants: wdPrintAutoTextEntries, wdPrintComments, wdPrintDocumentContent, wdPrintKeyAssignments, wdPrintProperties, or wdPrintStyles.
Copies Optional Variant. The number of copies to be printed.
Pages Optional Variant. The page numbers and page ranges to be printed, separated by commas. For example, "2, 6-10" prints page 2 and pages 6 through 10.
PageType Optional Variant. The type of pages to be printed. Can be one of the following WdPrintOutPages constants: wdPrintAllPages, wdPrintEvenPagesOnly, or wdPrintOddPagesOnly.
PrintToFile Optional Variant. True to send printer instructions to a file. Make sure to specify a file name with OutputFileName. This argument isn't available on the Macintosh unless QuickDraw GX is installed.
Collate Optional Variant. When printing multiple copies of a document, True to print all pages of the document before printing the next copy.
FileName Optional Variant. The path and file name of the document to be printed. If this argument is omitted, Word prints the active document. Available only with the Application object.
ActivePrinterMacGX Optional Variant. On the Macintosh, if QuickDraw GX is installed, specifies the printer to print to.
ManualDuplexPrint Optional Variant. Not used in the U.S. English version of Microsoft Word.
ALSO RUN A SEARCH on your hard drive
for the file vbawrd*.hlp, if you have the file then you can get all the help yourself!
Rob;-)
P.S. thanks very much for the points!
WordApp.ActiveDocument.Pri
expression Required. An expression that returns an Application, Document, or Window object.
Background Optional Variant. True to have the macro continue while Word prints the document.
Append Optional Variant. True to append the specified document to the file name specified by the OutputFileName argument. False to overwrite the contents of OutputFileName.
Range Optional Variant. The page range. Can be one of the following WdPrintOutRange constants: wdPrintAllDocument, wdPrintCurrentPage, wdPrintFromTo, wdPrintRangeOfPages, or wdPrintSelection.
OutputFileName Optional Variant. If PrintToFile is True, this argument specifies the path and file name of the output file. This argument isn't available on the Macintosh unless QuickDraw GX is installed.
From Optional Variant. The starting page number when Range is set to wdPrintFromTo.
To Optional Variant. The ending page number when Range is set to wdPrintFromTo.
Item Optional Variant. The item to be printed. Can be one of the following WdPrintOutItem constants: wdPrintAutoTextEntries, wdPrintComments, wdPrintDocumentContent, wdPrintKeyAssignments, wdPrintProperties, or wdPrintStyles.
Copies Optional Variant. The number of copies to be printed.
Pages Optional Variant. The page numbers and page ranges to be printed, separated by commas. For example, "2, 6-10" prints page 2 and pages 6 through 10.
PageType Optional Variant. The type of pages to be printed. Can be one of the following WdPrintOutPages constants: wdPrintAllPages, wdPrintEvenPagesOnly, or wdPrintOddPagesOnly.
PrintToFile Optional Variant. True to send printer instructions to a file. Make sure to specify a file name with OutputFileName. This argument isn't available on the Macintosh unless QuickDraw GX is installed.
Collate Optional Variant. When printing multiple copies of a document, True to print all pages of the document before printing the next copy.
FileName Optional Variant. The path and file name of the document to be printed. If this argument is omitted, Word prints the active document. Available only with the Application object.
ActivePrinterMacGX Optional Variant. On the Macintosh, if QuickDraw GX is installed, specifies the printer to print to.
ManualDuplexPrint Optional Variant. Not used in the U.S. English version of Microsoft Word.
ALSO RUN A SEARCH on your hard drive
for the file vbawrd*.hlp, if you have the file then you can get all the help yourself!
Rob;-)
P.S. thanks very much for the points!
ASKER
Thank you again!
ASKER
Hi Rob,
Here I am again with some points...
25 for this one:
- How can I terminate the Word application?
And another 25 for this question:
- How can I set a boolean for true when a specific piece of text has been found in a Word-document (something like "FIND")?
Thank you again...
I didn't have the help-file. Is there a website where I can download it?
Jan van Barchum.
Here I am again with some points...
25 for this one:
- How can I terminate the Word application?
And another 25 for this question:
- How can I set a boolean for true when a specific piece of text has been found in a Word-document (something like "FIND")?
Thank you again...
I didn't have the help-file. Is there a website where I can download it?
Jan van Barchum.