LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 120
Default Can't delete file?!!?

I'm running a macro in XL2007 in Vista which is manipulating a Word
document. At the end of everything, I want to delete the Word file.
The Word file has been properly saved through VBA unsing SaveAs - it
exists and I use the object to set ranges and such, so it's definitely
a good file.

But I can't delete it. I'm trying Kill and I'm trying
FSO.DeleteFile. For some reason, my computer keeps flipping my file
paths between C:\Users and C:\Documents and Settings, so I created two
strings and am using both operations on both strings. Debug.Print
shows good file paths. But the file won't go away!!

Any help is greatly appreciated!
Ed

On Error Resume Next
'Delete Word doc
strPath = objDoc.FullName
strFile = Replace(strPath, "Users", "Documents and Settings")

Debug.Print strPath
Debug.Print strFile
Stop
Stop

objDoc.Close SaveChanges:=wdSaveChanges
x = 0
Do
x = x + 1
objFSO.DeleteFile strPath, True
objFSO.DeleteFile strFile, True
Kill strPath
Kill strFile
If objFSO.FileExists(strPath) = False Then
If objFSO.FileExists(strFile) = False Then
Exit Do
End If
End If

If x = 6 Then
MsgBox "This program created a Word file." & _
vbCrLf & "Please delete this file."
Exit Do
End If
Loop
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 1 June 22nd 05 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 05:11 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:54 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:53 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:20 PM


All times are GMT +1. The time now is 12:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"