[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1178
  • Last Modified:

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?
0
ClassPublishing
Asked:
ClassPublishing
  • 2
1 Solution
 
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.
0
 
surfboredCommented:
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.

SB
0
 
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.
0
 
ClassPublishingAuthor Commented:
Thanks for your input.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now