Yes/No Msg Box upon Close. Send user to link if Yes chosen.

EMKP123

New Member
Joined
Mar 29, 2018
Messages
2
Hi All!

I am attempting to create a pop up message box when a user closes the spreadsheet. I'd like it to function by:

1. Showing the Yes/No message box when the user attempts to close the sheet.
2. Send user to a link (google doc) if Yes is chosen.
3. Close sheet if No is chosen.

Here is my attempt (full google link removed), but the the Yes action breaks down:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If MsgBox("Is this working?", _
vbQuestion + vbYesNo) = vbYes Then
objshell.Run ("https://docs.google.com/forms/d/e/....")
Else
Cancel = True
End If
End Sub

Admittedly I am a complete macro/VBa novice, so I pieced this together from various Google searches.

Any help is appreciated!!

Thanks!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
.
This is one way ...

Code:
Option Explicit


Sub Test3()
Dim answer As Variant
  answer = MsgBox("Yes = run Test1; No = run Test2", vbYesNo + vbQuestion, "Choose macro to run")
  If answer = vbYes Then
      Call Test1
   Else
     Call Test2
End If
End Sub


Sub Test1()
   Range("A1").Value = "A"
End Sub


Sub Test2()
   Range("A2").Value = "B"
End Sub
 
Upvote 0
Thanks for your reply Logit. Can you please clarify where this code would fit into my existing macro? How do I make sure this runs upon Close and where does the reference to the google doc (action after user chooses Yes) go?

Apologies for what may be simple questions; I don't have any experience in this area.



.
This is one way ...

Code:
Option Explicit


Sub Test3()
Dim answer As Variant
  answer = MsgBox("Yes = run Test1; No = run Test2", vbYesNo + vbQuestion, "Choose macro to run")
  If answer = vbYes Then
      Call Test1
   Else
     Call Test2
End If
End Sub


Sub Test1()
   Range("A1").Value = "A"
End Sub


Sub Test2()
   Range("A2").Value = "B"
End Sub
 
Upvote 0
.
Code:
Option Explicit




Sub Test3()
Dim answer As Variant
  answer = MsgBox("Yes = Link ; No = Quit", vbYesNo + vbQuestion, "Go to Google Link ?")
  If answer = vbYes Then
      Call Test1
   Else
     Call Test2
End If
End Sub




Sub Test1()
   'Code here for Google link
End Sub




Sub Test2()
   'Code here to quit program or other action.
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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