title: Opening Excel files from Visual Studio
body: <p>I have an applications that works fine using Windows 10 &amp; both Excel 2013 &amp; 2019 &amp; I am using visual studio 2019. I have just upgraded to Windows 11 and Office 2021 Pro &amp; the program will no longer open the same Excel file &amp; gives the following error message:-</p>
  <p>&quot;System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'&quot;</p>
  <p>No other changes have been made to the working program.</p>
  <p>The code concerned is:-</p>
  <pre><code>Public XL_Connection_string As String               
  Public XL_Connection As New OleDb.OleDbConnection
  
  Dim EXCEL_Connection_String_NoHeader As String = &quot;Provider=Microsoft.ACE.OLEDB.##.0; Data Source=&quot;&quot;XXX&quot;&quot;; Extended Properties=&quot;&quot;Excel ##.0 Xml;HDR=NO&quot;&quot;&quot;
  
  XL_Connection_string = Replace(EXCEL_Connection_String_NoHeader, &quot;XXX&quot;, strLoadVehiclesFileName) 
  
  XL_Connection_string = Replace(XL_Connection_string, &quot;##&quot;, OfficeVersion)
  XL_Connection.ConnectionString = XL_Connection_string                                                               
  XL_Connection.Open()                                                                                      
  </code></pre>
  <p>The program fails on the XL_Connection.Open() instruction.</p>
  <p>strLoadVehiclesFileName is set to the excel filename to be opened.
  OfficeVersion is set to 15 for Office 2013 &amp; 16 for Office 2021.</p>
  <p>Have I missed something that I need to change for Office 2021? Any help to solve this will be much appreciated.</p>