Hi,
Are you trying to get out of a UserForm? You probably have a Cancel CommandButton and the Window X.
If you are talking about the Cancel CommandButton, there is a Click event for that button. In the VBE, double click the button and view the code. At this point, you would run any cleanup routine and finally
I'm using the standard Message box. Here is the code I have.
Public Sub Timestamp()
'Init
Dim time As String
Dim Hours As String
Dim Min As String
Dim AMPM As String
Dim TestPeriod As String
time = ""
AMPM = "AM"
Title = "Enter the time"
Message = "Example, 1:30 AM = 1.30.0, 4:56 PM = 4.56.1 Click OK to exit."
Default0 = 0
time = InputBox(Message, Title, Default0)
If time = "0" Then GoTo Exitloop
TestPeriod = Mid(time, 2, 1)
'Tests for double digits
If TestPeriod <> "." Then
Hours = Left(time, 2)
Min = Mid(time, 4, 2)
If Hours = "12" Then AMPM = "PM"
GoTo Finish
End If
'For the rest of the times
Hours = Left(time, 1)
Min = Mid(time, 3, 2)
If Right(time, 1) = "1" Then AMPM = "PM"
GoTo Finish
Here is the code for it. The problem is when I click on cancel, it runs Finish. I've tried adding an If statment at the begining of finish, but the program ignores it.
I'm the only one that uses it, so I'm not worried about it being pretty or foul proof. But I do click on cancel every now and again instead of hitting the enter key, or clicking on OK.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.