locked
C# Interop Excel Sheet move and Sheet copy events RRS feed

  • Question

  • I am writing desktop application in C#, which watches some excel files and prevent user from performing some actions. This app should detect, when user moves or copies sheets from this file to another one. But so far as I understood, Interop.Excel does not provide needed events. Is there any workaround of this problem? Maybe, some similar events?

    Thank you in advance!

    Tuesday, July 4, 2017 1:29 PM

Answers

  • Hi PG_Develop,

    As a workaround, you could use Workbook.Protect to protect the workbook. The method could prevent users from viewing hidden worksheets, adding, moving, deleting, or hiding worksheets, and renaming worksheets, so it could prevet users from moving and copying a sheet. The code is just like

                    oXL = new Microsoft.Office.Interop.Excel.Application();             

                    oXL.Visible = true;

                    //Get a new workbook.

                    oWB = (Microsoft.Office.Interop.Excel.Workbook)(oXL.Workbooks.Add(""));

                    oWB.Protect("Pass01", Type.Missing, Type.Missing);   

    Best Regard,

    Terry

    • Marked as answer by PG_Develop Monday, July 17, 2017 1:22 PM
    Wednesday, July 12, 2017 10:14 AM

All replies

  • Hi PG_Develop,

    >> Interop.Excel does not provide needed events. Is there any workaround of this problem?

    As you know, Interop.Excel would not provide this function.

    Will the user open the workbook in the specific computer? If so, I think you could create VSTO solution which is Excel Add in, and then disable Copy and Move command.

    You could refer the link below for more information.

    # Disable Move or Copy Sheet.

    https://social.msdn.microsoft.com/Forums/office/en-US/9272ed62-4db7-4936-bd98-a9e6d7a2a323/disable-move-or-copy-sheet?forum=vsto

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 6, 2017 8:14 AM
  • Hi Edward,

    Thank you for the answer!

    Unfortunately, users would run this solution on external PCs, and I can not create VSTO add-in according to some other issues as well. Maybe, there is some other solution is used by community?

    BR,
    PG

    Monday, July 10, 2017 8:19 AM
  • Hi PG_Develop,

    As a workaround, you could use Workbook.Protect to protect the workbook. The method could prevent users from viewing hidden worksheets, adding, moving, deleting, or hiding worksheets, and renaming worksheets, so it could prevet users from moving and copying a sheet. The code is just like

                    oXL = new Microsoft.Office.Interop.Excel.Application();             

                    oXL.Visible = true;

                    //Get a new workbook.

                    oWB = (Microsoft.Office.Interop.Excel.Workbook)(oXL.Workbooks.Add(""));

                    oWB.Protect("Pass01", Type.Missing, Type.Missing);   

    Best Regard,

    Terry

    • Marked as answer by PG_Develop Monday, July 17, 2017 1:22 PM
    Wednesday, July 12, 2017 10:14 AM
  • Terry, hello

    Yes, actually, this could help.

    Thank you!

    BR,
    PG

    Monday, July 17, 2017 1:22 PM