none
Intercept drag and drop in Excel VSTO

    Question

  • The standard answer for "How do I register for a drag-and-drop" event in Excel seems to be to hook into the SheetChanged stuff. That only works of course, if Excel thinks the sheet was changed when you dropped something onto Excel. If you drag from another application, that is not always the case.

    Example, I drag something from an application that can have type of FileType. Since the application I am dragging and dropping from should also support dragging into the file-system, FileType it is... This means that Excel tries to (and succeeds depending on the file content) to open my dragged content as a file in a new worksheet. That's not even close to what I want. I want to embed some data in an OLE object in Excel.

    At the moment I have a "bad" solution for this. I hook into the Worksheet.Open event, check if my newly opened document is of the particular file type I am looking for, if it is, I will close the newly opened Worksheet and then go and embed the file in question.

    Is there a better solution? Can I actually hook into the drop event in Excel?

    Thursday, October 03, 2013 1:29 PM

Answers

  • Hi,

    Thanks for posting in the MSDN Forum.

    As far as I know, there is no better solution. Excel does not have event handlers that respond specifically to a drag-and-drop operation. As you said the standard answer for the solution is to hook the sheetchanged.

    Best regards

    Fei


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, October 04, 2013 9:04 AM

All replies

  • Hi,

    Thanks for posting in the MSDN Forum.

    As far as I know, there is no better solution. Excel does not have event handlers that respond specifically to a drag-and-drop operation. As you said the standard answer for the solution is to hook the sheetchanged.

    Best regards

    Fei


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, October 04, 2013 9:04 AM
  • This is sadly not the answer since it doesn't properly support D&D from external applications. If the data in the D&D operation is marked as FileType, Excel will try to open the file and the SheetChanged event is never fired.
    Monday, October 07, 2013 8:32 AM