Board index » delphi » Closing MsWord

Closing MsWord

What's the "Cleanest" way to close MsWord from another application (like an
installation application).

I still want word to go through its normal closing procedure (asking user to
save unsaved docs, ...)

Right now, I'm using sendmessage(wordhandle, wm_close, 0, 0);

Is that the best way??

Thanks...
--

Dan Gervais
Product Manager
MultiCorpora Inc
d...@multicorpora.ca

 

Re:Closing MsWord


Hi Dan!

Here is not so "clean" way to close word!

uses ComObj;

...............................

procedure TForm1.Button1Click(Sender: TObject);
var
 V: OleVariant;
begin
 try
     V := GetActiveOleObject('Word.Application');
     if not VarIsNull(V) then  V.Application.Quit;
  except
 end;
end;

Quote
Dan Gervais <d...@multicorpora.ca> wrote in message

news:7dtpml$cif7@forums.borland.com...
Quote
> What's the "Cleanest" way to close MsWord from another application (like
an
> installation application).

> I still want word to go through its normal closing procedure (asking user
to
> save unsaved docs, ...)

> Right now, I'm using sendmessage(wordhandle, wm_close, 0, 0);

> Is that the best way??

> Thanks...
> --

> Dan Gervais
> Product Manager
> MultiCorpora Inc
> d...@multicorpora.ca

Re:Closing MsWord


Quote
Dan Gervais wrote in message <7dtpml$c...@forums.borland.com>...
>What's the "Cleanest" way to close MsWord from another application (like an
>installation application).

>I still want word to go through its normal closing procedure (asking user
to
>save unsaved docs, ...)

>Right now, I'm using sendmessage(wordhandle, wm_close, 0, 0);

>Is that the best way??

There's nothing wrong with that at the moment, but it's
not going to be enough when Office 2000 becomes
widespread. You will have to search for and close
*every instance* of Word, since it will be an SDI
app.

--
Jeremy Collins

Re:Closing MsWord


Quote
> What's the "Cleanest" way to close MsWord from another application (like an
> installation application).

> I still want word to go through its normal closing procedure (asking user to
> save unsaved docs, ...)

> Right now, I'm using sendmessage(wordhandle, wm_close, 0, 0);

> Is that the best way??

Use

  postmessage( wordhandle, WM_SYSCOMMAND, SC_CLOSE, 0 );

This is 100% equivalent to a click on the close box and will run through
all the associated processing.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Re:Closing MsWord


Hi,

Do you know how to close 'Word.Basic' ?
I'm using the command:
    VarW := CreateOleObject ('Word.Basic');
    but it doesn't support the command  VarW.Quit !!!
   I would be happy if you have an answer for me.
  my e-mail: or...@nice.com

Best Regards ,

    Oren.

Quote
Azret wrote:
> Hi Dan!

> Here is not so "clean" way to close word!

> uses ComObj;

> ...............................

> procedure TForm1.Button1Click(Sender: TObject);
> var
>  V: OleVariant;
> begin
>  try
>      V := GetActiveOleObject('Word.Application');
>      if not VarIsNull(V) then  V.Application.Quit;
>   except
>  end;
> end;

> Dan Gervais <d...@multicorpora.ca> wrote in message
> news:7dtpml$cif7@forums.borland.com...
> > What's the "Cleanest" way to close MsWord from another application (like
> an
> > installation application).

> > I still want word to go through its normal closing procedure (asking user
> to
> > save unsaved docs, ...)

> > Right now, I'm using sendmessage(wordhandle, wm_close, 0, 0);

> > Is that the best way??

> > Thanks...
> > --

> > Dan Gervais
> > Product Manager
> > MultiCorpora Inc
> > d...@multicorpora.ca

Re:Closing MsWord


Hi,

Do you know how to close 'Word.Basic' ?
I'm using the command:
    VarW := CreateOleObject ('Word.Basic');
    but it doesn't support the command  VarW.Quit !!!
   I would be happy if you have an answer for me.
  my e-mail: or...@nice.com

Best Regards ,

    Oren.

Quote
Azret wrote:
> Hi Dan!

> Here is not so "clean" way to close word!

> uses ComObj;

> ...............................

> procedure TForm1.Button1Click(Sender: TObject);
> var
>  V: OleVariant;
> begin
>  try
>      V := GetActiveOleObject('Word.Application');
>      if not VarIsNull(V) then  V.Application.Quit;
>   except
>  end;
> end;

> Dan Gervais <d...@multicorpora.ca> wrote in message
> news:7dtpml$cif7@forums.borland.com...
> > What's the "Cleanest" way to close MsWord from another application (like
> an
> > installation application).

> > I still want word to go through its normal closing procedure (asking user
> to
> > save unsaved docs, ...)

> > Right now, I'm using sendmessage(wordhandle, wm_close, 0, 0);

> > Is that the best way??

> > Thanks...
> > --

> > Dan Gervais
> > Product Manager
> > MultiCorpora Inc
> > d...@multicorpora.ca

Re:Closing MsWord


VarW.Application.Quit
Quote
Hila Miler wrote in message <370D2220.A635E...@nice.com>...
>Hi,

>Do you know how to close 'Word.Basic' ?
>I'm using the command:
>    VarW := CreateOleObject ('Word.Basic');
>    but it doesn't support the command  VarW.Quit !!!
>   I would be happy if you have an answer for me.
>  my e-mail: or...@nice.com

>Best Regards ,

>    Oren.

>Azret wrote:

>> Hi Dan!

>> Here is not so "clean" way to close word!

>> uses ComObj;

>> ...............................

>> procedure TForm1.Button1Click(Sender: TObject);
>> var
>>  V: OleVariant;
>> begin
>>  try
>>      V := GetActiveOleObject('Word.Application');
>>      if not VarIsNull(V) then  V.Application.Quit;
>>   except
>>  end;
>> end;

>> Dan Gervais <d...@multicorpora.ca> wrote in message
>> news:7dtpml$cif7@forums.borland.com...
>> > What's the "Cleanest" way to close MsWord from another application
(like
>> an
>> > installation application).

>> > I still want word to go through its normal closing procedure (asking
user
>> to
>> > save unsaved docs, ...)

>> > Right now, I'm using sendmessage(wordhandle, wm_close, 0, 0);

>> > Is that the best way??

>> > Thanks...
>> > --

>> > Dan Gervais
>> > Product Manager
>> > MultiCorpora Inc
>> > d...@multicorpora.ca

Re:Closing MsWord


try it:

VarW.FileExit;

--
With best regards, Mike Shkolnik.
FIDO: 2:463/106.14
E-Mail: mshkol...@rs-ukraine.kiev.ua
        m...@woccu.freenet.kiev.ua
WEB: http://www.geocities.com/SiliconValley/Grid/3989

Hila Miler ??? a ???? <370D22B7.62039...@nice.com> ...

Quote
>Hi,

>Do you know how to close 'Word.Basic' ?
>I'm using the command:
>    VarW := CreateOleObject ('Word.Basic');
>    but it doesn't support the command  VarW.Quit !!!
>   I would be happy if you have an answer for me.
>  my e-mail: or...@nice.com

>Best Regards ,

>    Oren.

>Azret wrote:

>> Hi Dan!

>> Here is not so "clean" way to close word!

>> uses ComObj;

>> ...............................

>> procedure TForm1.Button1Click(Sender: TObject);
>> var
>>  V: OleVariant;
>> begin
>>  try
>>      V := GetActiveOleObject('Word.Application');
>>      if not VarIsNull(V) then  V.Application.Quit;
>>   except
>>  end;
>> end;

>> Dan Gervais <d...@multicorpora.ca> wrote in message
>> news:7dtpml$cif7@forums.borland.com...
>> > What's the "Cleanest" way to close MsWord from another application
(like
>> an
>> > installation application).

>> > I still want word to go through its normal closing procedure (asking
user
>> to
>> > save unsaved docs, ...)

>> > Right now, I'm using sendmessage(wordhandle, wm_close, 0, 0);

>> > Is that the best way??

>> > Thanks...
>> > --

>> > Dan Gervais
>> > Product Manager
>> > MultiCorpora Inc
>> > d...@multicorpora.ca

Other Threads