title: Cannot call Excel AddIn in Excel macro called form Access macro
body: <p>I'am creating an Access database where different clients should be stored later, currently they're stored in an Excel workbook.</p>
  
  <p>I have access to the data of an SQL database (I can't change anything there) where the current Excel sheet gets client name and other informations from and I want that too in my Access database. The problem is that there is only an interface for Excel  to connect to the database. It's an Excel AddIn with a macro and I don't have access to its code.</p>
  
  <p>My solution was that i run the code in Access calling a macro in an Excel sheet and that calls the Addin macro. But it's not working...</p>
  
  <p>It runs the Excel macro perfecly but when that tries to run the other Excel macro it fails. Sometimes (it's different when I change the Excel macro code) I get this error in the Access VBA editor:</p>
  
  <blockquote>
    <p>Runtime error '-2147417851 (80010105)'<br>
    The method 'Run' for the object '_Application' is failed</p>
  </blockquote>
  
  <p><strong>Note:</strong> I have translated the text from german to english so it's probably not the exact error text.</p>
  
  <p>And sometimes i get an error from Excel which mean the sheet which contains the AddIn macro could not be found but the addin is installed and when I debug trough the macro it works perfectly.</p>
  
  <p>The AddIn is installed I have checked that with <code>Application.Addins(5).Name</code> in a for loop.</p>
  
  <p>I have searched for 2 days now and I don't get further, I haven't even found someone with the same problem so far.</p>
  
  <p>Here is my Access VBA code:</p>
  
  <pre><code>Public Sub getData(portfolioNumber As String)
  
  Dim xlApp As Object
  
  Dim sFile As String
  Dim sClientName As String
  Dim sOtherData As String
  
  sFile = CurrentProject.Path &amp; "\ImportSheet.xlsm"
  Set xlApp = CreateObject("Excel.Application")
  xlApp.Workbooks.Open sFile
  xlApp.Cells(5, 6).Value = portfolioNumber
  xlApp.Cells(6, 6).Value = portfolioNumber
  
  xlApp.Run "importAMSData"
  sClientName = xlApp.Cells(8, 8).Value
  sOtherData = xlApp.Cells(8, 9).Value
  xlApp.Workbooks.Close
  
  MsgBox (sClientName &amp; " " &amp; sOtherData)
  
  Set xlApp = Nothing
  
  End Sub
  </code></pre>
  
  <p>And here is my Excel VBA code which should call the other macro:</p>
  
  <pre><code>Public Sub importAMSData()
  
  Dim iLastRow As Double
  Dim iLastCol As Double
  Dim dErrNo As Double
  
  Dim ws As Worksheet
  Dim wb As Workbook
  
  Dim aAddin As AddIn
  
  Dim wbOpen As Boolean
  
  Set ws = ThisWorkbook.Sheets(1)
  
  ws.Activate
  
  iLastRow = ws.Cells(ws.Rows.Count, 2).End(xlUp).Row
  iLastCol = ws.Cells(7, ws.Columns.Count).End(xlToLeft).Column
  
  If iLastRow &gt; 7 And iLastCol &gt; 1 Then
  ws.Range(ws.Cells(8, 1), ws.Cells(iLastRow, iLastCol)).ClearContents
  End If
  
  wbOpen = False
  
  ws.Cells(1, 2).Select
  </code></pre>
  
  <p>The AddIn should be installed by default but after it haven't worked I tried to reinstall it</p>
  
  <pre><code>Set aAddin = Application.AddIns.Add("C:\Program Files\Microsoft Office\Office14\XLSTART\SPEZM.xlam")
  
  aAddin.Installed = True
  
  Application.Run "SPEZM.xls!import"
  </code></pre>
  
  <p>I have also tried: </p>
  
  <pre><code>aAddin.Application.Run "import"
  </code></pre>
  
  <p>Often (means always if the other error not occurs) here comes an error saying that Excel haven't found Sheetname.xls but the AddIn is installed I have checked that.</p>
  
  <p>I thank you for you're help and sorry for the long question.</p>