Davers
Well-known Member
- Joined
- Sep 17, 2002
- Messages
- 1,165
Hi everyone...I've created a bit o' code that saves a file using cell references to set the name. I'd like an error handler on it that uses the Yes/No buttons so I can replace the file if I want by pressing yes. Currently my code looks like the below:
I don't know how to set the yes button on the MsgBox so it will replace the file with I hit the button, and not replace the file when I hit the no button...
Any ideas?!
Thanks,
Dave
Code:
Dim myFile As String
Dim myDir As String
Dim myErr As String
Dim fs As New Scripting.FileSystemObject
myErr = Range("D7").Value
myDir = Range("D6").Value
On Error GoTo HandleErr
fs.CreateFolder myDir
myFile = Worksheets("Main").Range("D8").Value
ThisWorkbook.SaveAs myFile
HandleErr:
If Err.Number = 58 Then
MsgBox Err.Description & " - " & myErr & " - " & "Would you like to replace the exisiting file?", vbYesNo
Else
Resume Next
End If
End Sub
I don't know how to set the yes button on the MsgBox so it will replace the file with I hit the button, and not replace the file when I hit the no button...
Any ideas?!
Thanks,
Dave