title: How to export data from Excel to Access via Excel Macro when multiple instances of Excel are open
body: <p>I am using an Excel macro to define a data range in Excel and then call "objAccess.DoCmd.TransferSpreadsheet" to import the data from this range  into an Access table. This import does not work all of the time.</p>
  
  <p>I have come to the conclusion that the macro works fine when there is only one instance of Excel open. However, the data import fails when another instance is already open. In the latter case the Access database opens up and the Excel file from which I run the macro is being reopened (in read-only mode) in the other Excel instance. There is no actual error but the desired import is not being carried out. Why does this happen?</p>
  
  <pre><code>Sub Excel_2_Access()
  
      Dim strPath As String
      Dim strwbPath As String
      Dim strRange As String
      Dim objAccess As Access.Application
      Dim wbActive As Workbook
  
  'get database path
      strPath = Worksheets("error").Range("Access_DB_Path").Value &amp; "\" &amp; Worksheets("error").Range("Access_DB").Value
  
  'open database
      Set objAccess = New Access.Application
      Call objAccess.OpenCurrentDatabase(strPath)
      objAccess.Visible = True
  
  'access import
      Worksheets("error").Columns("P:P").Calculate
      Set wbActive = ActiveWorkbook
      strwbPath = Application.ActiveWorkbook.FullName
      strRange = "error!M2:M" &amp; (Worksheets("error").Range("WKN_count").Value + 2)
      Call objAccess.DoCmd.TransferSpreadsheet(acImport, 8, "WKN_Mapping", strwbPath, True, strRange)
      objAccess.Forms("MX_Import").Refresh
  
  End Sub
  </code></pre>
  
  <p>As the macro is fairly short I have included the entire code for your reference. However, I don't think the way the range is specified or names are provided is really relevant to the question.</p>
  
  <p>The desired outcome would be to have an Excel macro in place that carries out the transfer from Excel to Access no matter if there are other instances of Excel open or not. </p>
  
  <p>Is there such a thing as the primary instance of Excel (the first one that was opened) which has a special status? Is there a way to provide the specific Excel instance the workbook is in when calling the Access function from Excel? Or is there a more reliable way to transfer the data which generally avoids this problem with multiple instances?</p>