Word Macro Delete File

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

theos340

Thread Starter
Joined
Apr 11, 2008
Messages
2
I am try to write a Word macro that when the user opens an existing file in Folder A and presses a specific key the file is saved in Folder B and the file in folder A is deleted.

I can't get the delete part working. The new file is saved using the ActiveDocument.Saveas method, but It seems that the original file is still locked by word and therefore can not be deleted.

I've tried using the following but no luck

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile (FILENAME), True

Any ideas?
 

theos340

Thread Starter
Joined
Apr 11, 2008
Messages
2
(Original File would be located at c:\FolderA\text.doc

'-----------------------------------------------------------------

strUnproceededFile = ActiveDocument.FullName

ActiveDocument.SaveAs FileName:="c:\FolderB\test.doc"

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile (strUnproceededFile), True

'-----------------------------------------------------------------

I've also tried the Kill command.
 
Joined
Sep 4, 2003
Messages
4,916
The code works fine for me. Have you tried to manually close the document using code

Code:
Sub DeleteDoc()

strUnproceededFile = ActiveDocument.FullName

strDocName = ActiveDocument.Name

ActiveDocument.SaveAs FileName:="c:\Test\test.doc"

For Each wdDoc In Application.Documents
If wdDoc.Name = strDocName Then
wdDoc.Close
End If
Next wdDoc


Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile (strUnproceededFile), True

End Sub
Regards,
Rollin
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top