Hello,
I have an OnError GoTo statement. If there is an error with the MkDir (aka, the file already exists), then I want it to go to the ErrMsg that asks if the user wants to continue or not. If they continue, the files will overwrite. If they don't, the macro ends. This is working perfectly right now. The problem I have is when there is NO error. If that's the case, then the file gets created as expected, but then it sends the ErrMsg anyway. I don't want it to send the error message when there is no error. How do I fix this?
(side note: when the error exists, I want it to show the ErrMsg, NOT exit the sub)
I have an OnError GoTo statement. If there is an error with the MkDir (aka, the file already exists), then I want it to go to the ErrMsg that asks if the user wants to continue or not. If they continue, the files will overwrite. If they don't, the macro ends. This is working perfectly right now. The problem I have is when there is NO error. If that's the case, then the file gets created as expected, but then it sends the ErrMsg anyway. I don't want it to send the error message when there is no error. How do I fix this?
(side note: when the error exists, I want it to show the ErrMsg, NOT exit the sub)
VBA Code:
'Create new month folder
strDirname = Format(Sheets("Inputs").Range("B2"), "yyyy-MM") & " Claims Prod Metrics" ' New folder name
On Error GoTo ErrMsg
MkDir "\\test.test.net\sites\departments\test\Test\Test Test\Test Test\" & strDirname
ErrMsg: ans = MsgBox("This file already exists. Would you like overwrite the existing set of PDFs for the month/year that you generated?", vbYesNoCancel, "DUPLICATE FILE")
Select Case ans
Case vbYes
ThisWorkbook.Sheets("Inputs").Range("M2").Value = UserValue
Case vbNo
MsgBox ("Files were not saved.")
Exit Sub
Case vbCancel
MsgBox ("Files were not saved.")
Exit Sub
End Select
'Continue on with more code from here