Message box dead end!

Akashwani

Well-known Member
Joined
Mar 14, 2009
Messages
2,911
Hi,

I keep trying and searching BUT,
I have the following problem..

I want the user to click YES to enter the workbook.
If they click NO, I want the workbook to close.

This is what I have so far...

Dim t As Date
Private Sub Workbook_Open()
Dim s As String
ans = MsgBox("Do you want to Enter?", vbYesNo, "My Workbook?")
If ans = vbYes Then
End If
How do I get the workbook to close if they click NO?
s = InputBox("To Login In Enter your first name")
t = Now
Const strRightAnswer As String = "Ottawa"
Dim strAnswer As String
While Not (strRightAnswer = strAnswer)
strAnswer = InputBox("What is the capital of Canada?")
If Not (LCase(strRightAnswer) = LCase(strAnswer)) Then MsgBox "Incorrect answer please try again."
Wend
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "You have been active for " & Format(Now - t, "nn") & " minutes and " & Format(Now - t, "ss") & " seconds."
Dim res
res = MsgBox(" Have you finished?", vbYesNo)
If res <> vbYes Then Cancel = True
End Sub


Thanks for you time.

Ak
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Unless you are using "ans" someplace else, try:

Code:
If Not MsgBox("Do you want to enter?", _
              vbYesNo + vbQuestion, "My Workbook") = vbYes _
                Then ThisWorkbook.Close False
 
Upvote 0
Thanks for the replies.
This forum never fails to help this novice.

Both work BUT,
When NO is clicked the "time box" and "have you finished box" appear.
Is it possible to click NO and the workbook closes straight away?

Thanks

Ak
 
Upvote 0
At the top of ThisWorkbook module:

Rich (BB code):
Dim bolOpening as Boolean

In the opening event code:
Rich (BB code):
    If Not MsgBox("do you etc...", vbYesNo + vbQuestion, "") = vbYes Then
        bolOpening = True
        ThisWorkbook.Close False
    End If
In the BeforeClose code, surround the current stuff that you don't want done with:
Rich (BB code):
If Not bolOpening Then
 
    '...Statements...
 
End if
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top