title: How to programmatically load an XLL file into Excel?
body: <p>How to programmatically load an XLL file into Excel when it is linked to other DLLs.
  Using c# winforms application + Excel Automation I’m creating Excel Application object. Then I’m using:</p>
  
  <pre><code>bool bXllLoadSuccess = _excelApp.RegisterXLL(_pathXll);
  </code></pre>
  
  <p>It is OK when XLL is self-contained. The problem occurs when it depends on other DLLs. Even when I put them into the same folder Excel doesn’t want to pick them up.
  I tried to do following before loading the XLL but it doesn’t help:</p>
  
  <pre><code>_excelApp.DefaultFilePath = Path.GetDirectoryName(_pathXll);
  </code></pre>
  
  <p>I have tried this one as well:</p>
  
  <pre><code>Directory.SetCurrentDirectory(Path.GetDirectoryName(_pathXll));
  </code></pre>
  
  <p>Dependency walker shows no issues – all required files are in the same folder with the XLL.
  Any ideas?</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPD:</strong> I tried copying all requried dlls into a folder and then added it's path to PATH variable. Didn't help :)</p>
  
  <p><strong>UPD2:</strong> I tried to change current directory for both c# app and Excel application object at the same time. Didn't help :(</p>