Hello Everyone,
I am having a problem with WordApplicatio component. I am using Delphi 10.
I can get the WordApplication to open with the Document template that I select, but Word is behind my app and when I close
Word I get an RPC Server not available errror and after that a pointer violation and then access violations until I reset the IDE.
Here is the code I am using:
procedure TTestLetterForm.Button1Click(Sender: TObject);
var
FileName: oleVariant;
begin
//Letter2Report.Print;
if OpenDialog.Execute = True then
begin
FileName := OpenDialog.FileName;
WordApplication1.Documents.Open(FileName,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
WordApplication1.Visible := True;
end;
end;
How do I stop the errors and how do I get data to the word document which is a letter with multiple fields.
Any help with this will be very appreciated as I am under the gun to get this app working.
Thanks and have a great day!
Keith Hancock
Edited by: Keith Hancock on Oct 10, 2011 8:13 AM
Edited by: Keith Hancock on Oct 11, 2011 6:35 AM
0 Keith10/11/2011 1:36:47 PM
> {quote:title=Keith Hancock wrote:}{quote}
> Hello Everyone,
>
> I am having a problem with WordApplicatio component. I am using Delphi 10.
>
> I can get the WordApplication to open with the Document template that I select, but Word is behind my app and when I close
>
> Word I get an RPC Server not available errror and after that a pointer violation and then access violations until I reset the IDE.
>
> Here is the code I am using:
>
> procedure TTestLetterForm.Button1Click(Sender: TObject);
> var
> FileName: oleVariant;
> begin
> //Letter2Report.Print;
>
> if OpenDialog.Execute = True then
> begin
> FileName := OpenDialog.FileName;
>
> WordApplication1.Documents.Open(FileName,EmptyParam,
> EmptyParam,EmptyParam,EmptyParam,
> EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
> EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
>
> WordApplication1.Visible := True;
>
> end;
> end;
>
> How do I stop the errors and how do I get data to the word document which is a letter with multiple fields.
>
> Any help with this will be very appreciated as I am under the gun to get this app working.
>
> Thanks and have a great day!
>
> Keith Hancock
>
> Edited by: Keith Hancock on Oct 10, 2011 8:13 AM
>
> Edited by: Keith Hancock on Oct 11, 2011 6:35 AM
Hello
As I can see there is some sort of misunderstanding.
When you are using WordApplication component you launch instance of MS Word at the same moment.
And if you try to close MS Word before your program hasn't done all operations you will get errors listed above.
So you can launch MS Word in tray if you set
WordApplication1.Visible := False;
If you are using old format of office documents then you have no other choice but to run instance of MS Word at the same time
and edit your document with WordApplication methods.
If you are using new format then try using OpenXML based code. Then you won't have to launch MS Word and still could make all operations.
Good luck!