automating document management

R

RBM

Brief (hopefully) question here. Thanks in advance.
My goal is to write a macro that will, after having opened a series of
documents within Word, allow me to do certain actions on them
(proof-reading, printing, etc. - all to be done manually) and then,
upon closing, automatically save them to a different folder (on the
network) while deleting them from their original local folder. In
effect, therefore, part of the process of closing the document will be
to move it to a new location on a network server. I've worked out
virtually all of this, but I cannot seem to delete the file from it's
original location. I believe that this is because, even after saving
it under a new name (actually, same name but different location),
there is still a tilde-preceded reference to the file in the original
folder, thus seemingly indicating that the original file is open. As
such, I cannot delete it until I've closed it (but once it's closed
the macro that I wish to delete it will no longer be running and thus
the process won't be done seamlessly and automatically. Hopefully, I'm
making myself clear. Any ideas?
 
R

RBM

That really was less that clear, wasn't it?

What I'd like to do, in effect, is to use VBA within a Word macro to
move the Active Document into a different folder, one on a network
server, and then delete the original from its original location. My
problem seems to be that I can't delete the original when any
reference to it is still active within Word (even if the actual open
document is now in another folder) and I can't use the macro to delete
automatically after the document has been closed. Any ideas?
 
H

hals_left

I just tried this in a module and it worked OK.
You ned to set a ref to Microsoft Scripting Runtime


I'm not sure if you can call it from a document_close event though as
the doc will still be open at that time.


Private Sub foo()

Dim strFile
strFile = CStr(ActiveDocument.Path & "/" & ActiveDocument.Name)
ActiveDocument.SaveAs ("c:/foo2.doc")

Dim objFile As Scripting.FileSystemObject
Set objFile = New Scripting.FileSystemObject
objFile.DeleteFile (strFile)

End Sub
 
J

Jay Freedman

If the macro is in a global template, or in a regular template that's
used to create a new file that is not one of the ones being edited,
then the macro won't stop when the edited documents are all closed.
The only scenario that doesn't work is having the macro in the
template used to create the edited documents (because closing the last
of those documents also closes the template).
 
R

RBM

Thanks, I think that's what I needed to hear. It'll take me a few days
to find the time to work on this, but I believe I can make it work.
 

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