title: How to connect Excel with locked Access database using VBA?
body: <p>I have an Access database with password ("1234") and I want to connect an Excel file, using VBA, to extract data.</p>
  
  <p>If I unprotect the Access file I can connect with something like this</p>
  
  <pre><code>path = ThisWorkbook.Path &amp; "\KCBD.accdb"
  cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; path &amp; ";Persist Security Info=False;"
  
  Set Cn = New ADODB.Connection
  Cn.Open cs
  </code></pre>
  
  <p>When I protect Access file with a password I don't know how to do the connection.</p>
  
  <p>I tried</p>
  
  <pre><code>Ruta = ThisWorkbook.Path &amp; "\KCBD.accdb"
  cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; Ruta &amp; ";Persist Security Info=False;" &amp; "Password=1234;"
  
  Set Cn = New ADODB.Connection
  Cn.Open cs
  </code></pre>
  
  <p>In the <code>Cn.Open cs</code> line this error makes me stop:</p>
  
  <blockquote>
    <p>Runtime Error '-2147217843 (80040e4d)'</p>
  </blockquote>