Reputation: 3
Been researching previous treads on this issue but I still cannot find a solution. Any help would be appreciated.
Trying to use Application.Run
to to call a sub called SortSOEDM
from a module called SOMacros
in an Addin called CDVAddins2010.Xlam
that was published to me by a colleague. I've tried dozens of iterations of the following line using the module name and sub name in different positions. Can not get it to work. Any ideas what I'm doing wrong?
Application.Run ("CDVAddins2010.xlam!SortSOEDM")
Issue resolved by Doovers. See his answer below.
Upvotes: 0
Views: 3820
Reputation: 8675
Application.Run
expects the following arguments:
Application.Run([Macro], [Arg1], [Arg2], ...)
The reason you are getting the "Argument not Optional" error is that CDVAddins2010.xlam!SortSOEDM
Sub
or Function
is expecting a parameter to be passed to it.
So for example, if SortSOEDM
looked like this:
Sub SortSOEDM(str As String)
MsgBox str
End Sub
To call this you would use:
Dim str As String
str = "Test Message"
Application.Run "CDVAddins2010.xlam!SortSOEDM", str
Or if it was a function:
Function SortSOEDM(str As String)
SortSOEDM = "The string you passed to this function was: " & str
End Function
Which you would call like this:
Dim str As String
str = "Test Message"
Dim strReturn As String
strReturn = Application.Run("CDVAddins2010.xlam!SortSOEDM", str)
MsgBox strReturn
Note that you only use () for a function.
Upvotes: 1
Reputation: 459
In the VBA editor, add a reference to the addin: Tools > References, then Browse and change the file type to .xlam. Use this dialog to find the add-in on your hard disk.
You can then call the subroutine without Application.Run:
' call the subroutine
SortSOEDM
Upvotes: 0