title: Calling a Method from a C# Dll in Excel VBA
body: <p>I am attempting to use a method in VBA from a C# dll that I created. The file is COM visible and referenced in my VBA file. </p>
  
  <p>Here is my VBA code:</p>
  
  <pre><code>Private Declare Function COMPaste Lib "C:\Blah\bin\x86\Debug\TestCOMExposure.dll" Alias "Countdown" (ByVal left As Integer) As Integer
  Sub TestA()
  Dim instance As TestCOMExposure.TestProgram
  Set instance = New TestCOMExposure.TestProgram
  MsgBox (instance.COMPaste)
  
  End Sub
  </code></pre>
  
  <p>To see my method in C# dll:</p>
  
  <pre><code>namespace TestCOMExposure
  {
      [System.Runtime.InteropServices.ComVisible(true)]
      [System.Runtime.InteropServices.ClassInterface(
      System.Runtime.InteropServices.ClassInterfaceType.None)]
      [ProgId("TestCOMExposure.TestProgram")]
      [Guid("4EFE27BF-A442-4F93-9A55-A00BD2D7160A")]
      public class TestProgram : ITestProgram
      {
          public void Countdown()
          {
              int i = 60;
              int day = 3;
              int left = i - day;
              Console.WriteLine("Saba has {0} days left", left);
              Console.Read();
          } 
  </code></pre>
  
  <p>And my interface code:</p>
  
  <pre><code>[System.Runtime.InteropServices.ComVisible(true)]
  [Guid("20DF3D06-0DC6-445D-9149-F23A34B0624F")]
  public interface ITestProgram
  {
      void Countdown();
  }
  </code></pre>
  
  <p>The error that I get when I run my VBA code is" Automation Error The system cannot find the file specified. Please let me know what I am doing wrong.</p>