delete file in close event

T

tb2000

Is there any way to delete a file that's not needed any longer e.g. during a
document_close event? Apparently the file needs to be really closed first
before it can be removed from the file system and thats what I am struggling
with.
Any help welcome!
tb
 
J

Jean-Guy Marcil

tb2000 was telling us:
tb2000 nous racontait que :
Is there any way to delete a file that's not needed any longer e.g.
during a document_close event? Apparently the file needs to be really
closed first before it can be removed from the file system and thats

It kinds of make sense, no? Windows cannot a delete a file if it is being
used. Then, as soon as it is totally closed, the code stops executing.... If
the code resides in the document itself, you have a perfect example of a
Catch-22 situation!

Where is the code residing?
In the Document_Close event of the attached template?
In a global template?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

tb2000

Jean-Gui, merci beaucoup!
The issue I am trying to resolve is that I actually want to assign a new
document a file name (pre-defined so to say) without having to create a
presence/file on disk - just to provide a default when the user finally does
a save command or exits the file (into the doc changed save y/n dialog).
Alternatively I thought I could delete the file after determining it's
unwanted on disk...
Theo
 
T

tb2000

btw: the code resides outside, in an Outlook VBA class that wraps my worddoc
object...
 
J

Jean-Guy Marcil

tb2000 was telling us:
tb2000 nous racontait que :
Jean-Gui, merci beaucoup!
The issue I am trying to resolve is that I actually want to assign a
new document a file name (pre-defined so to say) without having to
create a presence/file on disk - just to provide a default when the
user finally does a save command or exits the file (into the doc
changed save y/n dialog). Alternatively I thought I could delete the
file after determining it's unwanted on disk...
Theo

The easiest would be to store the file name and path (FullName), then do
your SaveAs to create the file with the desired name and finally use Kill to
delete the other file.

For example:

Dim OldFile As String

OldFile = Documents("Doc1.doc").FullName

Documents("Doc1.doc").SaveAs "NewDoc.doc"

Kill OldFile


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

tb2000

Merci beaucoup!

Anyways, I trapped the _close and _beforeSave events and handle the save
portion there, not saving anything unless explicitely desired by the user;
trapping the beforeSave event allows me to pass filepath and name to the
SaveAs built in dialog. A little messy but seemingly works.

Cheers!
Theo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top