An Oldie But A Goodie

Here is an oldie but a goodie to start the New Year. If you still use xlm functions in your apps, you can use this code to run them in VBA. Happy New Year!

 

Function RunXLM(fname As String, bBuiltIn As Boolean, ParamArray xArg())

 

    Dim n As Integer

    Dim num_arguments As Integer

 

    num_arguments = UBound(xArg)

   

    With Application

 

    If bBuiltIn Then

 

        Select Case num_arguments + 1

        Case 0

            RunXLM = .ExecuteExcel4Macro(fname)

        Case 1

            fname = Mid(fname, 1, Len(fname) – 1) & “,”

            RunXLM = .ExecuteExcel4Macro(fname & xArg(0) & “)”)

        Case 2

            fname = Mid(fname, 1, Len(fname) – 1) & “,”

            RunXLM = .ExecuteExcel4Macro(fname & xArg(0) & “,” & xArg(1) & “)”)

        Case 3

            fname = Mid(fname, 1, Len(fname) – 1) & “,”

            RunXLM = .ExecuteExcel4Macro(fname & xArg(0) & “,” & xArg(1) & “,” & xArg(2) & “)”)

        Case Else

            RunXLM = “”

        End Select

 

    Else

 

        Select Case num_arguments + 1

        Case 0

            RunXLM = .Run(fname)

        Case 1

            RunXLM = .Run(fname, xArg(0))

        Case 2

            RunXLM = .Run(fname, xArg(0), xArg(1))

        Case 3

            RunXLM = .Run(fname, xArg(0), xArg(1), xArg(2))

                                              

        Case 4

            RunXLM = .Run(fname, xArg(0), xArg(1), xArg(2), xArg(3))

                                              

        Case 5

            RunXLM = .Run(fname, xArg(0), xArg(1), xArg(2), xArg(3), xArg(4))

                                              

        Case Else

            RunXLM = “”

        End Select

 

    End If

   

    End With

 

End Function

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s