kill document when it's open

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have code that checks for the existence of a document and, if it exists,
deletes it. However, if that document is open it can't be killed. Is there a
way to programmatically close the document so that it can be deleted?
 
It is possible to do this by using API code to find the running
application which has the program open and killing it, but I wouldn't
advise this.

The right response to finding the document open is to tell the user
that the document is open and that you want to delete it (presumably
so that you can create an updated version), and to give him the
opportunity either to close the file or to abort your code.

I have code that checks for the existence of a document and, if it exists,
deletes it. However, if that document is open it can't be killed. Is there a
way to programmatically close the document so that it can be deleted?

Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 
You can use this code to activate the application you want to close, such
Microsoft word, and then use the Alt + F4 to close it

AppActivate "Microsoft Word" ' Activate Microsoft word
SendKeys "%{F4}", True
 
Back
Top