Board index » delphi » To close an open file in MS word

To close an open file in MS word

Hello All,

I have two procedures. In one of the procedure i have written code for
launching MS WORD something like this

Procedure procedure1
begin
 MsWord := CreateOleObject('Word.Application');
 MsWord.Documents.Open('C:\Temp\Test1.doc');
 MsWord.ActiveDocument.SaveAs(C:\Temp\Test2.doc) ;
 MsWord.Visible := True;
end;

This opens the file Test2.doc. Now in the another procedure i want to
rename this file Test2.doc, with the help of "RenameFile" Function.
But if the file Test2.doc is open, it gives an error. How can i close
this file Test2.doc.

Regards
Prasad

 

Re:To close an open file in MS word


Try :

Quote
>  MSWord:= CreateOleObject('Word.Application');

     MSWord.DisplayAlerts:= False;

Quote
>  MsWord.Documents.Open('C:\Temp\Test1.doc');
>  MsWord.ActiveDocument.SaveAs(C:\Temp\Test2.doc) ;
>  MsWord.Visible := True;

    MSWord.Quit;
    MSWord:= Unassigned;

to close ms word,  >  = your code + miine.

I do not have word installed so I cannot test this.
Thanks
7 of  Zero

Quote
"Prasad Kulkarni" <prasad.kulka...@mailcity.com> wrote in message

news:a8274029.0205230444.5b114547@posting.google.com...
Quote
> Hello All,

> I have two procedures. In one of the procedure i have written code for
> launching MS WORD something like this

> Procedure procedure1
> begin
>  MsWord := CreateOleObject('Word.Application');
>  MsWord.Documents.Open('C:\Temp\Test1.doc');
>  MsWord.ActiveDocument.SaveAs(C:\Temp\Test2.doc) ;
>  MsWord.Visible := True;
> end;

> This opens the file Test2.doc. Now in the another procedure i want to
> rename this file Test2.doc, with the help of "RenameFile" Function.
> But if the file Test2.doc is open, it gives an error. How can i close
> this file Test2.doc.

> Regards
> Prasad

Other Threads