|
-
Sep 15th, 2004, 02:58 PM
#1
Thread Starter
Junior Member
Capture Response to EXCEL ALERTS [RESOLVED]
When the user clicks the close "X" in the upper right hand corner of the excel application window... I get the alert.. "Do you want to save the changes made to XXX.XLS?" - I don't mind this but would like to capture the users response to "YES", "NO" or "CANCEL" so that I can direct my program to perform the proper actions. HOW DO I CAPTURE THE USER RESPONSE?
Thanks in advance,
Richard
Last edited by ssei1; Sep 16th, 2004 at 10:41 AM.
-
Sep 15th, 2004, 11:48 PM
#2
For starters, totally do-able. I even added a way to disable the
right-click in any cell!
Step1: Write code in the "ThisWorkBook" module to declare a class to capture our events.
Step2: Write class to initialize and attach to Excel.
Step3: Write Close event and code to handle users response to the save question.
Step4: Enjoy! 
VB Code:
'Name: 'ThisWorkBook' Object Module
Option Explicit
Private RD As clsMyEvents
Private Sub Workbook_Open()
Set RD = New clsMyEvents
MsgBox "My Events Created!", vbOKOnly + vbInformation, "My Excel Events"
End Sub
'Name: clsMyEvents
'Instancing: Private
Option Explicit
Public goXL As Excel.Application
Public WithEvents MyEvents As Excel.Workbook
Private Sub Class_Initialize()
Set goXL = GetObject(, "Excel.Application")
Set MyEvents = goXL.ActiveWorkbook
End Sub
Private Sub MyEvents_BeforeClose(Cancel As Boolean)
Dim iResp As Integer
iResp = MsgBox("RobDog888: Do you want to save your workbook?", vbYesNoCancel + vbQuestion, "My Excel Events")
If iResp = vbYes Then
goXL.ActiveWorkbook.Save
If goXL.ActiveWorkbook.Saved = True Then
MsgBox "Saved!", vbOKOnly + vbInformation, "My Excel Events"
Else
MsgBox "Error Saving Workbook!" & vbNewLine & "Sorry!", vbOKOnly + vbCritical, "My Excel Events"
End If
ElseIf iResp = vbCancel Then
Cancel = True
End If
End Sub
Private Sub MyEvents_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
MsgBox "No Right-Clicking!", vbOKOnly + vbInformation "My Excel Events"
Cancel = True
End Sub
If you have any trouble I can attach the working Workbook example.
VB/Outlook Guru!
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 16th, 2004, 10:40 AM
#3
Thread Starter
Junior Member
-
Sep 16th, 2004, 12:45 PM
#4
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|