Unanswered Problems after enabling editing from protected view

  • Friday, January 13, 2012 11:07 PM
     
     

    I have a VSTO app-level Excel add-in. It works as expected in Excel 2007 and Excel 2010. However, if I open a workbook downloaded from an external website via HTTPS using Excel 2010, the workbook opens in Protected View (PV).

      (I understand what Protected View is. I have read the blog articles posted in other threads.)

    I understand that the Excel events for this workbook are not fired. So, my add-in cannot effectively interact with the workbook while it is in PV. So far, so good.

    However, my users need a way forward from this state. Turning off PV is not recommended. Trusted locations is not practical in the real world with lots of end-users.

    When the user clicks "Enable Editing", the workbook is released from the sandbox and events begin to fire. Great!

    Unfortunately, this point is where the problems begin also. My code starts to get COMExceptions where none are expected.

       Note: this same code works fine for workbooks that were never in PV.

    Example: I am seeing a COMException when calling the Activate() method on the Excel._Worksheet object.

    Has anyone else seen unexpected exceptions after enabliing editing for a PV workbook?

    Any known workarounds?

    Thanks!

All Replies

  • Sunday, January 15, 2012 3:59 AM
     
     

    Hello,

    What's the exception? Is it "object reference not set to an instance of an object"? If so, you need to check if you get the sheet object correctly.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader
  • Monday, January 16, 2012 12:58 AM
     
     
    No. It's not an NRE. As mentioned above, it's a COMException.
  • Wednesday, May 02, 2012 2:05 AM
     
      Has Code

    Any updates on this issue? I am hitting the same issue with Protected View.

    I have a simple test add-in to demonstrate this issue  (The code might seem to be meaningless). Please not this is a Excel 2007 add-in.

    using Excel = Microsoft.Office.Interop.Excel;
    using System.Windows.Forms;
    
    namespace ExcelAddIn
    {
        public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
               this.Application.WorkbookOpen += HandleWorkbookOpened;
            }
    
            private void HandleWorkbookOpened (Excel.Workbook interopWorkbook)
            {
               Excel._Worksheet sheet = interopWorkbook.ActiveSheet;
               sheet.Activate ();
               MessageBox.Show ("Success");
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            
            #endregion
        }
    }

    The add-in works well within Excel 2007, but not with the Protected View of Excel 2010.

    When I open a workbook in PV within Excel2010, I see the workbook is read-only and my add-in is disabled, expected. But then I click "Enable Edit" and expect to see the "Success" message, however, in debugger I just see ComException is thrown from "sheet.Activate()" with error code 0x800A03EC, no "Success" message.  This ComException is not seen when I open a trusted workbook with Excel2010 (regular view).

    Could anyone help with this issue please?

    Thanks,

    Yixuan