PDA

View Full Version : Delete the Word file upon exiting it.



mikeburg
10-21-2007, 02:40 PM
I need to delete the file when exiting it. However, when I put the following VBA in auto_Close, I get Run-Time Error 70 Permission denied:

Sub AutoClose()
ThisDocument.Saved = True 'To skip save question
Kill ("MikeFaxDoc.doc")
End Sub

Please, someone help come up with the VBA that deletes the file when exiting it, I am new to VBA for Word.

Thanks a million. mikeburg

lucas
10-21-2007, 03:18 PM
Now why would you want to do that Mike?

fumei
10-21-2007, 08:01 PM
I am kind of curious myself. I am not even sure it can be done. It has to be still alive to carry out instructions.

In fact, I am pretty sure it can NOT be done, as it does not make sense that it could.

AutoClose - or the newer Document_Close - or ANY procedure must finish and terminate with the End Sub. How can it finish, if you delete the container that is actually running it? It can't...so...it denies you permission to carry out that instruction. VBA is not suicidal.

Why not delete it with code from normal.dot? Or another file code module? What exactly is going on here?

mikeburg
10-22-2007, 05:39 PM
We have a word document on the network that in auto_open I have the user's unique copy created from it as follows:

ActiveDocument.SaveAs FileName:=Environ("UserName") & "FaxDoc.doc", FileFormat:=wdFormatDocument

Then when the user prints the file, I want their file deleted automically upon exiting.

I was hoping for a simple VBA approach. Can you help?

Thanks a bunch. mikeburg

lucas
10-22-2007, 05:47 PM
Hi Mike,
How about capturing the print event and then just close the file (using code just after printing) without saving changes...I'm just offering suggestions. This alternative would be instead of saving the file as a different filename.

TonyJollans
10-22-2007, 11:36 PM
Sounds to me like you should be using a template instead of editing an existing file - then you wouldn't need to save it and then you wouldn't need to delete it.

mikeburg
10-23-2007, 04:23 PM
The templet approach might work.

However, merely opening the file & exiting without saving after printing is the way we have been doing it. The problem is when two or more users want to use the special Fax file at the same time. That's why I have been saving the file with another name immediately upon a user opening it.

Thanks a million for any other ideas you have. mikeburg

TonyJollans
10-24-2007, 12:19 AM
The problem is when two or more users want to use the special Fax file at the same time.
That's why templates were invented. OK I exaggerate :)

Point is that when you use the wrong tool for the job you end up with problems.

fumei
10-24-2007, 09:00 AM
"That's why templates were invented. OK I exaggerate "

Oh, I don't know. If it is, it is not much an exaggeration.

TonyJollans
10-24-2007, 11:50 AM
LOL