Hi - I'm trying to make a workbook remain open if the user wants to fix mistakes before submitting the file. This is my current code - a couple of queries are refreshed, the user is asked if the input is complete, and then a cell is checked to see if there are errors. If there are errors, a message box comes up asking if they'd like to keep the file open and fix the errors. The vba works up to this point, but I can't get the "cancel = True" to keep the file open. It merely saves and closes.
The additional complication is that, if the file is error-free, the file can be submitted per another message box. This part currently works as well when the file has no errors. It's just the getting the file to stay open that I'm struggling with. Would appreciate any help! Here is my code! The "saveas2" at the bottom is just another macro that saves the file in a certain spot.
The additional complication is that, if the file is error-free, the file can be submitted per another message box. This part currently works as well when the file has no errors. It's just the getting the file to stay open that I'm struggling with. Would appreciate any help! Here is my code! The "saveas2" at the bottom is just another macro that saves the file in a certain spot.
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.Connections("Query - New").Refresh
ActiveWorkbook.Connections("Query - New1").Refresh
If (MsgBox("Is the input complete?", vbYesNo) = vbNo) Then
Exit Sub
Else
If Range("PYChecker") > 0 Then
aok = MsgBox("Before the file is submitted, you will need to fix your errors. Would you like to do so now?", vbYesNo)
If (aok = vbYes) Then
Cancel = True
Exit Sub
End If
End If
End If
If (MsgBox("Would you like to submit the file?(Just click yes if so)", vbYesNo) = vbYes) Then
If (MsgBox("Thank you! When you click OK, this file will be submitted.", vbOKOnly) = vbOK) Then
saveas2
End If
End If
End Sub