mcelligott
Programmer
Here is what I attempting to do, to help you understand my coding:
but when it actually tries to kill the file, it says "Run-time error 53: File not found".
I have tried several variations of the same macro code and keep getting the same error. I have also made sure I could manually delete the file from the old folder while the workbook was still open and I was able to do that. I copied the MyFile variable directly from the previous macro that saves it to the old folder initially (so it would be exactly the same). I have also copied and pasted the folder locations directly from windows so there would be no typing errors.
Any help anyone can offer would be greatly appreciated.
* I save the file to a new folder using the saveas method (combining three cells to make the name).
* I verify the file saved to the new folder as expected.
* I verify the file exists in the old folder as expected (it currently sends a message saying it exists - this is a temporary step).
* As long as the file exists based on the test in the previous step, I attempt the kill command to delete the file from the old folder.
but when it actually tries to kill the file, it says "Run-time error 53: File not found".
Code:
Sub SaveForOpsMgr()
Dim MyDir As String
Dim MyOldDir As String
Dim MyFile As String
Dim KillFile As String
MyDir = "\\ecd911\911\Operations\DOR - Ops Mgr Review\"
MyOldDir = "\\ecd911\911\Operations\DOR - Supv Review\"
MyFile = Range("B3") & ", " & Range("F3") & " DOR for" & Format(Range("B5"), " mm-dd-yyyy")
KillFile = MyOldDir & MyFile
If IsEmpty(ThisWorkbook.Sheets(1).Range("L57")) Then
MsgBox "You forgot to sign the DOR."
ActiveSheet.Range("L57").Select
GoTo out2
End If
nResult = MsgBox( _
Prompt:="Are you sure ?", _
Buttons:=vbYesNo)
If nResult = vbNo Then
Exit Sub
Else
nResult = vbYes
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=MyDir & MyFile
End If
' Confirm File was saved to the DOR folder
If Dir(MyDir & MyFile) = "" Then
If Dir(KillFile) = "" Then
MsgBox KillFile & " exists. Attempting to delete file."
Kill KillFile
ActiveWorkbook.Close
Else
MsgBox KillFile & " does not exist."
End If
Else
MsgBox "DOR did not save!"
End If
out2:
End Sub
I have tried several variations of the same macro code and keep getting the same error. I have also made sure I could manually delete the file from the old folder while the workbook was still open and I was able to do that. I copied the MyFile variable directly from the previous macro that saves it to the old folder initially (so it would be exactly the same). I have also copied and pasted the folder locations directly from windows so there would be no typing errors.
Any help anyone can offer would be greatly appreciated.