excel - accessing bessel function from vba
excel - accessing bessel function from vba
(OP)
I have the analysis tool-pak add-in and the analysis VBA toolpak add-in loaded.
I can access bessel functions from my worksheet. For example
besseli(1.2,0)
But I cannot access them from VBA.
besseli(1.2,0) in the immediate window gives "error - sub or function not defined)
application.worksheetfunction.besseli(1.2,0) gives error: "object does not support thsi propery or method"
How can I get bessel in vba?
I can access bessel functions from my worksheet. For example
besseli(1.2,0)
But I cannot access them from VBA.
besseli(1.2,0) in the immediate window gives "error - sub or function not defined)
application.worksheetfunction.besseli(1.2,0) gives error: "object does not support thsi propery or method"
How can I get bessel in vba?
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: excel - accessing bessel function from vba
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: excel - accessing bessel function from vba
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: excel - accessing bessel function from vba
CODE
Dim range1 As Range
Dim double1 As Double
Dim answer As Double
Worksheets("sheet1").Select
Set range1 = Range("A1")
double1 = 1.2
range1.Formula = "=+besseli(" & double1 & ",0)"
answer = range1.Value
Debug.Print answer
End Sub
I checked a little more on why vba didn't recognize besseli, when the whole purpose of the vba analysis toolpak is to give us access to the functions in the regular analysis toolpak.
I found the answer in "Excel 2002 Power Programming with VBA" by John Walkenbach, Chapter 30 ("Frequently Asked Questions") which states:
Now I'm curious how we were supposed to know about this mysterious atpvbaen.xls? Is it in the help somewhere that I missed?
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: excel - accessing bessel function from vba
I tried the following and it gives a compiler error on the line involving besseli (with atpvbaen.xls unchecked), but works fine to ouptut the sin if I comment out the besseli line.
(Generates a compiler error which can be eliminated by commenting out the besseli line or by checking atpvbaen.xls).
So apparently the evaluate(formulastring) function does not send the formulastring to the same parser/interpretter as the excel worksheet does. Weird.
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: excel - accessing bessel function from vba
Once you check the add-in Analysis ToolPak - VBA, then check the atpvbaen.xls Reference, shouldn't this statement work?
besselS = Application.WorksheetFunction.BesselI(a, b)
Object doesn't support this property or method.
I understand the workaround, which works of course, but all that business about adding the Anal. Toolpak-VBA and that mysterious atpvbaen.xls seems like just a waste of time if you can't access functions like the Bessel functions with a simple worksheetfunction call.
RE: excel - accessing bessel function from vba
http://w
There is a description of the steps to use this mysterious atpvbaen.xls. Once you check the Analysis ToolPak VBA and teh atpvbaen.xls Reference, you can see what has been added to your list of available functions by going to View/Object Browser, then select atpvbaen.xls in the pull down menu in the upper left of the Object Browswer. Lower right, you will see a list of available functions. At the very bottom, it shows you how to use those functions. To access Bessel functions, don't be a dope like I was and use:
stuff = Application.WorksheetFunction.BesselI(a, b)
instead, use:
stuff = BesselI(a, b)
right in your program, as you would use Application.WorksheetFunction.