none
Excel 2016 Protected View message in .NET 2015 windows application - Enable Editing in code RRS feed

  • Question

  • I have a VB.Net program that was able to open and read the date in an Excel 2007 spreadsheet with Office 365 2016 installed on the computer

    After the update to Windows KB4041676 was installed the same code now creates an error and is not able to open the Excel Spreadsheet

    The only workaround I have found is to open the Sheet in Excel first, enable editing, and while the sheet is open the VB.NET program is able to open the file and read the data. If I close the open sheet in Excel and the try to open the file again VB.NET the sheet will not open and returns an error

    How do you enable editing allowed on the Excel Sheet through code in VB.NET so that it can once gain be opened without first having to open the sheet in Excel and enabling editing?

    I am using 

                        Dim MyConnection As New OleDbConnection
                        Dim MyCommand As New OleDbDataAdapter
                        MyConnection = New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;  Data Source=" & openFileDialog1.FileName & "; Extended Properties=""Excel 8.0;""")
    
                        If MyConnection.State = ConnectionState.Closed Then MyConnection.Open()
    
                        MyCommand = New OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
                        MyCommand.TableMappings.Add("Table", "TestTable")
    
                        DtSet = New DataSet
                        MyCommand.Fill(DtSet)
    

    Where before the KB update that code worked, the code now gives the error

    System.Data.OleDb.OleDbException was unhandled

      ErrorCode=-2147467259

      HResult=-2147467259

      Message=Unexpected error from external database driver (1).

      Source=Microsoft JET Database Engine

    I need to find away to make the program enable editing on the file in code before opening the file in code to emulate what I have to do after the KB installed by opening the file first in Excel and enabling editing

    Any suggestions on the code required would be appreciated

    Tuesday, October 17, 2017 3:39 PM

Answers

  • Hi DavidMills11,

    It seems that it is JET Database Engine driver issue due to the KB update.

    As a workaround, you could uninstall the KB update or use ACE OLEDB for connecting.

    Here is the example.

            MyConnection = New OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;
    Data Source=C:\Users\Administrator\Desktop\Book1.xlsx; Extended Properties=""Excel 12.0 XML;""")Best Regards,

    Terry


    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.

    • Marked as answer by DavidMills11 Thursday, October 19, 2017 5:59 AM
    Wednesday, October 18, 2017 9:45 AM
  • thank you for the information - solved the problem of  Microsoft.ACE.OLEDB.12.0 not registered by downloading and installing the runtimeMicrosoft Access Database Engine 2010 Redistributable

    Regards

    David

     
    • Marked as answer by DavidMills11 Thursday, October 19, 2017 6:00 AM
    Wednesday, October 18, 2017 4:42 PM

All replies

  • Hi DavidMills11,

    It seems that it is JET Database Engine driver issue due to the KB update.

    As a workaround, you could uninstall the KB update or use ACE OLEDB for connecting.

    Here is the example.

            MyConnection = New OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;
    Data Source=C:\Users\Administrator\Desktop\Book1.xlsx; Extended Properties=""Excel 12.0 XML;""")Best Regards,

    Terry


    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.

    • Marked as answer by DavidMills11 Thursday, October 19, 2017 5:59 AM
    Wednesday, October 18, 2017 9:45 AM
  • Thank you for the reply and the example

    I am getting an error message - Microsoft.ACE.OLEDB.12.0 not registered

    I have Office 365 2016 - what provides Microsoft.ACE.OLEDB.12.0

    Regards

    David

    Wednesday, October 18, 2017 2:34 PM
  • thank you for the information - solved the problem of  Microsoft.ACE.OLEDB.12.0 not registered by downloading and installing the runtimeMicrosoft Access Database Engine 2010 Redistributable

    Regards

    David

     
    • Marked as answer by DavidMills11 Thursday, October 19, 2017 6:00 AM
    Wednesday, October 18, 2017 4:42 PM
  • Hi DavidMills11,

    I'm glad to hear that your issue has been resolved. I would suggest you mark helpful reply or your solution as answer to help other developers use this forum efficiently. If you have any other new issue, please feel free to post threads to let us know. Thanks for understanding.
    Best Regards,
    Terry


    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, October 19, 2017 1:40 AM