为什么UBound()不允许我将Application.Run()作为参数传递?

时间:2017-01-23 23:30:12

标签: r excel-vba vba excel

我正在尝试通过BERT运行R代码。

这是我在UI自定义编辑器中的代码:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
 <ribbon startFromScratch="false">
 <tabs>
 <tab id="RTrader" label="RTrader">
 <group id="myGroup" label="My Group">
 <button id="button1" label="New Button" size="large" onAction="myRCode" imageMso="Chart3DColumnChart" />
 </group> 
 </tab>
 </tabs>
 </ribbon>
</customUI>

这实际上在Excel功能区中创建了一个新按钮。我试图在新模块下的VBA编辑器中运行此代码:

Sub myRCode(control As IRibbonControl)
   Dim a As Variant
   Dim theLength As Integer
   ThisWorkbook.Sheets("Sheet1").Range("B1:B10000").ClearContents
   a = Application.Run("BERT.Call", "myFunction")
   theLength = UBound(a, 1) + 1
   ThisWorkbook.Sheets("Sheet1").Range("B1:B" & theLength).Value = a
End Sub

..然而它给我错误13'类型不匹配。据我所知,Variants能够通过UBound作为参数,但在这种情况下它不起作用。

0 个答案:

没有答案