# ExcelRun::failed: Type mismatch >> error when calling an Excel macro from Mathematica

I have a macro in a module within an Excel file (called "test.xlsm", saved on my desktop) that takes one argument as a string:

Sub macro1(str As String)
Range("A1").Value = str
End Sub


Using Mathematic Link for Excel add-in (version 3.5.0), I would like to run this macro directly from Mathematica 10.3:

In[1]:= << ExcelLink
ExcelOpen["\\\\Mac\\Home\\Desktop\\Test.xlsm"]
ExcelRun["macro1", "string"]


However, when I run this code from within Mathematica, I get the following type mismatch error:

Out[2]:= -Book: Test.xlsm-

ExcelRun::failed: Type mismatch >>
Out[3]:= \$Failed


When I call the macro from within Excel from another macro, it runs without any error.

I would appreciate any pointers or possible solutions. Thank you.

• @Yves Klett thank you for the quick response. As requested, I supplied all the code which reproduces the problem on my end. – Lucas Feb 13 '16 at 9:42
• Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – user9660 Feb 13 '16 at 10:38
• @Lucas thank you for the edit, let´s hope someone can help you there. And also a (if somewhat belated) welcome to the site! – Yves Klett Feb 13 '16 at 10:50
• try making and running a macro with no arguments. – george2079 Feb 13 '16 at 15:22
• @george2079 The string type was the problem! I updated macro1 to have its argument "As Variant" and now ExcelRun["macro1", arg1] works. Thank you for the suggestion! – Lucas Feb 13 '16 at 18:04

Sub macro1(str As Variant)