Application.Run的Addins宏

时间:2015-03-19 10:06:42

标签: excel-vba vba excel

一直在研究此问题的先前步骤,但我仍然无法找到解决方案。任何帮助将不胜感激。

尝试使用Application.Run从名为SortSOEDM的模块中调用名为SOMacros的子组件,该模块名为CDVAddins2010.Xlam,由同事发布给我。我已经使用不同位置的模块名称和子名称尝试了以下几行的几十次迭代。无法让它发挥作用。我有什么想法吗?

Application.Run ("CDVAddins2010.xlam!SortSOEDM")

Doovers已解决问题。请参阅下面的答案。

2 个答案:

答案 0 :(得分:0)

在VBA编辑器中,添加对插件的引用:工具>引用,然后浏览并将文件类型更改为.xlam。使用此对话框查找硬盘上的加载项。

然后您可以在没有Application.Run的情况下调用子例程:

' call the subroutine
SortSOEDM

答案 1 :(得分:0)

Application.Run需要以下参数:

Application.Run([Macro], [Arg1], [Arg2], ...)

您收到“Argument not Optional”错误的原因是CDVAddins2010.xlam!SortSOEDM SubFunction期望将参数传递给它。

例如,如果SortSOEDM看起来像这样:

Sub SortSOEDM(str As String)
    MsgBox str
End Sub

要调用它,您将使用:

Dim str As String
str = "Test Message"
Application.Run "CDVAddins2010.xlam!SortSOEDM", str

或者如果它是一个功能:

Function SortSOEDM(str As String)
    SortSOEDM = "The string you passed to this function was: " & str
End Function

你会这样称呼:

Dim str As String
str = "Test Message"
Dim strReturn As String
strReturn = Application.Run("CDVAddins2010.xlam!SortSOEDM", str)
MsgBox strReturn

请注意,您只对函数使用()。

相关问题