Delete file using VBA in template - 2nd post

R

Rick Wilson

I have a macro that saves the currently opened file with
a new name and into a different directory. I then need it
to delete the original file. If I try to delete the
original before closing the renamed file, I get an error.
If I try to delete it after closing the renamed file,
it's as if the entire macro stops. The file is built on
the template that's used to create the document.
My macro is not in Normal.dot but rather in
the template that the document is based on. I'm wondering
if by closing the document that the macro may be ending
early. Deletion of the file is the last thing the macro
should do. How can this be accomplished?

The macro runs and I get the 1st message box but not the
second.

Here's the code I'm using:
ChangeFileOpenDirectory FilePath 'Change to proper dir
ActiveDocument.SaveAs FullReportName,
FileFormat:=wdFormatDocument
On Error GoTo CleanUpErrorHandler
MsgBox ("Got Here 1")
ActiveDocument.Close ' closes currently opened file
MsgBox ("Got Here 2")
ChangeFileOpenDirectory Path
MsgBox (DelFile)
Kill DelFile ' deletes original file
End
 
D

Doug Robbins - Word MVP

Hi Rick,

Where is the macro? In the document? in the template from which the
document is created? in an addin?

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
R

Rick Wilson

The macro is in the Template from which the document is created. It does
several other functions before it deletes the original file.

I've had macros in the past that I put into each users Normal.dot (18
users). This has been a maintenance nightmare. Therefore, I wanted to put
this macro in the specific template, put the template on the network and set
each users' Word workgroup setting to point to this directory. Thereby the
template will display in the File - New dialog box.

Thanks for your help.
Rick
 
D

Doug Robbins - Word MVP

Hi Rick,

With the macro in the template from which the document is created, then when
the document is closed, the reference to the template is also deleted and
the balance of the code will not be executed.

If you put the macro in and add-in (a template that is saved in the Word
Startup folder, you should be able to do what you want.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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