Creating a temporary file with VBA

This is best described by way of example:

I have a template document called TemplateC1.doc (don't want it to be .DOT if possible because don't want to be forced to keep it with all the other Word templates). The 'template' is full of VBA code which does all sorts of fancy stuff. A Delphi program will make a copy of TemplateC1.doc into a specific folder (for argument's sake let's say it is c:\ClientFolders\Smith) and call it C1.doc. Delphi program then opens up Word with the c1.doc as a parameter. Some fancy VBA code is executed upon opening and the user is then expected to work in C1.doc. The problem is, if the user wants to discard C1.doc, he can't because it has been created and Word doesn't recognise it as a temporary file.

My question is:
When Delphi creates c1.doc, is there some way that it can create it, so Word knows it is a temporary file and treats it as such (i.e. if user says he doesn't wish to save, it will disappear forever!)
Alternatively, if I cannot create a temporary file, is there a way of self-destructing a document?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shanmuga SundaramDirector of Software EngineeringCommented:
why is it not possible to delete the file if the user discards it?. For this you can handle a flag and check for the flag. if it user discards then set the flag to false and if the flag is set to false then delete the discarded document. I think this will help you.
The problem you're having here is that the document didn't start out as a temporary document, but rather as an already existing document.

Try opening Word, creating a new blank document (via the VBA if you like) and then pasting in the information that is originally found in your C1.doc. Then it should behave like a temporary document when the user attempts to close/abandon the document.

ClassPublishingAuthor Commented:
Thanks Surfbored and shasunder for your input.  Surfbored, the problem with VBA is that it is executed from within itself in an interpretive way. Your document contains the macros which are to be executed. Shasunder, deleting the file afterwards is the avenue I did take but reversed out of quickly when I realised how dangerous deleting documents can be. The timing of this could be tricky. I have decided to go down the DOT route although this has its problems.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ClassPublishingAuthor Commented:
Thanks for your input.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.