T
Trefor
I have the following code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
msg = "You are attempting to manually exit a DCA file." & vbCrLf &
vbCrLf
msg = msg + "This file type should only be closed through the DCA
menu. Failure to do so risks the LOSS of data!" & vbCrLf & vbCrLf & vbCrLf
msg = msg + "Press 'Ok' to Continue" & vbCrLf & vbCrLf
msg = msg + "Press 'Cancel' to abort the file save and return to
excel." & vbCrLf & vbCrLf
Ret = MsgBox(msg, vbExclamation + vbOKCancel)
If Ret = vbOK Then
' Proceed with file closure
ElseIf Ret = vbCancel Then
Cancel = True
End If
End Sub
If I hit Cancel I get the expected result, if I hit Ok, runs through to the
End Sub and goes back up to the beginning and runs the whole macro again. So
you effectively get asked twice on closing the file.
What am I doing wrong? Any ideas welcome, thanks.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
msg = "You are attempting to manually exit a DCA file." & vbCrLf &
vbCrLf
msg = msg + "This file type should only be closed through the DCA
menu. Failure to do so risks the LOSS of data!" & vbCrLf & vbCrLf & vbCrLf
msg = msg + "Press 'Ok' to Continue" & vbCrLf & vbCrLf
msg = msg + "Press 'Cancel' to abort the file save and return to
excel." & vbCrLf & vbCrLf
Ret = MsgBox(msg, vbExclamation + vbOKCancel)
If Ret = vbOK Then
' Proceed with file closure
ElseIf Ret = vbCancel Then
Cancel = True
End If
End Sub
If I hit Cancel I get the expected result, if I hit Ok, runs through to the
End Sub and goes back up to the beginning and runs the whole macro again. So
you effectively get asked twice on closing the file.
What am I doing wrong? Any ideas welcome, thanks.