Results 1 to 4 of 4

Thread: Capture Response to EXCEL ALERTS [RESOLVED]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Location
    MA
    Posts
    20

    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.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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:
    1. 'Name: 'ThisWorkBook' Object Module
    2. Option Explicit
    3.  
    4. Private RD As clsMyEvents
    5.  
    6. Private Sub Workbook_Open()
    7.     Set RD = New clsMyEvents
    8.     MsgBox "My Events Created!", vbOKOnly + vbInformation, "My Excel Events"
    9. End Sub
    10.  
    11.  
    12. 'Name: clsMyEvents
    13. 'Instancing: Private
    14. Option Explicit
    15.  
    16. Public goXL As Excel.Application
    17.  
    18. Public WithEvents MyEvents As Excel.Workbook
    19.  
    20. Private Sub Class_Initialize()
    21.     Set goXL = GetObject(, "Excel.Application")
    22.     Set MyEvents = goXL.ActiveWorkbook
    23. End Sub
    24.  
    25. Private Sub MyEvents_BeforeClose(Cancel As Boolean)
    26.     Dim iResp As Integer
    27.     iResp = MsgBox("RobDog888: Do you want to save your workbook?", vbYesNoCancel + vbQuestion, "My Excel Events")
    28.     If iResp = vbYes Then
    29.         goXL.ActiveWorkbook.Save
    30.         If goXL.ActiveWorkbook.Saved = True Then
    31.             MsgBox "Saved!", vbOKOnly + vbInformation, "My Excel Events"
    32.         Else
    33.             MsgBox "Error Saving Workbook!" & vbNewLine & "Sorry!", vbOKOnly + vbCritical, "My Excel Events"
    34.         End If
    35.     ElseIf iResp = vbCancel Then
    36.         Cancel = True
    37.     End If
    38. End Sub
    39.  
    40. Private Sub MyEvents_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    41.     MsgBox "No Right-Clicking!", vbOKOnly + vbInformation "My Excel Events"
    42.     Cancel = True
    43. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Location
    MA
    Posts
    20

    Wink THANKS

    GREAT SOLUTION - CAN'T THANK YOU ENOUGH !!!!!!!!!!

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No prob.
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width