Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to catch these events?

how to catch these events?

Scheduled Pinned Locked Moved C#
csharptestingtoolstutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abhiram_nayan
    wrote on last edited by
    #1

    Can we catch(or overload the event handler) the (Yes, No, Cancel) button click events of Microsoft Excel when the user clicks the Close(X) button on the top right corner of the ms excel workbook? Am basically building an excel automation add-in to ms excel using c#.

    L 1 Reply Last reply
    0
    • A abhiram_nayan

      Can we catch(or overload the event handler) the (Yes, No, Cancel) button click events of Microsoft Excel when the user clicks the Close(X) button on the top right corner of the ms excel workbook? Am basically building an excel automation add-in to ms excel using c#.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Excel isn't written in C#, and you can't just hook into the code like you would with something that you have written yourself. You can hook into native code, you can get the handle of the buttons of the closedialog and send a click-message, but I don't know if it is possible to hook into the WndProc of Excel. This is not a simple assignment for the weekend!

      I are troll :)

      A 1 Reply Last reply
      0
      • L Lost User

        Excel isn't written in C#, and you can't just hook into the code like you would with something that you have written yourself. You can hook into native code, you can get the handle of the buttons of the closedialog and send a click-message, but I don't know if it is possible to hook into the WndProc of Excel. This is not a simple assignment for the weekend!

        I are troll :)

        A Offline
        A Offline
        abhiram_nayan
        wrote on last edited by
        #3

        hey Eddy, thanks for replying. I've been scratching my head since... Basically, I want to create an xml for every excel sheet the user saves and when he reopens the excel sheet, I am supposed to open the corresponding xml. Thus, I used the WorkbookBeforeClose http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook_events(VS.80).aspx[^]event and my whole aim is achieved if *the user is saving the sheet first and then closing ms excel* However, the problem is, when he is trying to save the sheet by: Press the Close(X) button and when the pop up which says "Do you want to save changes to filename.xls? 'Yes' 'No' 'Cancel'" shoots up and IF he is choosing 'Yes' here, am not able to achieve the same. The reason being, the WorkbookBeforeClose event is invoked as soon as he presses the Close(X) button on the top right corner of ms excel. I want to somehow be able to know whether the user has chosen 'Yes' or 'No' from the pop-up. Can I?! If yes, kindly tell me how?! Regards.

        L 1 Reply Last reply
        0
        • A abhiram_nayan

          hey Eddy, thanks for replying. I've been scratching my head since... Basically, I want to create an xml for every excel sheet the user saves and when he reopens the excel sheet, I am supposed to open the corresponding xml. Thus, I used the WorkbookBeforeClose http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook_events(VS.80).aspx[^]event and my whole aim is achieved if *the user is saving the sheet first and then closing ms excel* However, the problem is, when he is trying to save the sheet by: Press the Close(X) button and when the pop up which says "Do you want to save changes to filename.xls? 'Yes' 'No' 'Cancel'" shoots up and IF he is choosing 'Yes' here, am not able to achieve the same. The reason being, the WorkbookBeforeClose event is invoked as soon as he presses the Close(X) button on the top right corner of ms excel. I want to somehow be able to know whether the user has chosen 'Yes' or 'No' from the pop-up. Can I?! If yes, kindly tell me how?! Regards.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I'm no expert on Excel-interop, but I'm sure that some of those hang round here. In the meantime, there are two interesting events in that same documentation; - BeforeSave I guess this one is also fired if the user chooses "Yes", but not if he chooses "Cancel" or "No". - ShutDown Signals that the application is about to shut down. Perhaps you could do the same with a FileSystemWatcher, watching all the XLS-files in the specified directories for updates. Anyone else any idea's?

          I are troll :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups